From 9be943426ae7c786e43537b6231656cb42db1460 Mon Sep 17 00:00:00 2001 From: Florian Obser Date: Wed, 25 Sep 2019 14:41:41 +0000 Subject: Do not leak cur_ns in case of malformed lease file. Found by llvm's scan-build. OK deraadt, benno --- sbin/unwind/frontend.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'sbin') diff --git a/sbin/unwind/frontend.c b/sbin/unwind/frontend.c index 4ed5f5d2e64..9532e1ce0ff 100644 --- a/sbin/unwind/frontend.c +++ b/sbin/unwind/frontend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend.c,v 1.23 2019/09/25 14:40:59 florian Exp $ */ +/* $OpenBSD: frontend.c,v 1.24 2019/09/25 14:41:40 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser @@ -1018,6 +1018,7 @@ parse_dhcp_lease(int fd) if (strcmp(toks[1], "domain-name-servers") == 0) { if((p = strchr(toks[2], ';')) != NULL) { *p='\0'; + free(cur_ns); cur_ns = strdup(toks[2]); } } @@ -1041,11 +1042,16 @@ parse_dhcp_lease(int fd) if (epoch + lease_time > now ) { free(ns); ns = cur_ns; - } else /* expired lease */ + cur_ns = NULL; + } else { + /* expired lease */ free(cur_ns); + cur_ns = NULL; + } } } free(line); + free(cur_ns); if (ferror(f)) log_warn("getline"); -- cgit v1.2.3