diff options
author | 2017-08-30 18:06:10 +0000 | |
---|---|---|
committer | 2017-08-30 18:06:10 +0000 | |
commit | df2b2f85686d0d30033fd45a01472783ab479ecb (patch) | |
tree | c561ded5499ebd4b78fef06d3052c813fbca2577 | |
parent | Guard FEMACSUSEMETA uses behind #ifdef EMACS (diff) | |
download | wireguard-openbsd-df2b2f85686d0d30033fd45a01472783ab479ecb.tar.xz wireguard-openbsd-df2b2f85686d0d30033fd45a01472783ab479ecb.zip |
Refactor interface_status() to call freeifaddrs()
before returning, plugging a memory leak.
Problem reported by Kamil Shakirov via bugs@.
tweaks, testing & ok jca@
-rw-r--r-- | sbin/dhclient/dhclient.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 2795dbc73ee..1913d4b3bb2 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.496 2017/08/26 14:45:57 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.497 2017/08/30 18:06:10 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -235,31 +235,30 @@ interface_status(char *name) { struct ifaddrs *ifap, *ifa; struct if_data *ifdata; + int ret; if (getifaddrs(&ifap) != 0) fatalx("getifaddrs failed"); for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { - if ((ifa->ifa_flags & IFF_LOOPBACK) || - (ifa->ifa_flags & IFF_POINTOPOINT)) - continue; - - if (strcmp(name, ifa->ifa_name) != 0) - continue; - - if (ifa->ifa_addr->sa_family != AF_LINK) - continue; - - if ((ifa->ifa_flags & (IFF_UP|IFF_RUNNING)) != - (IFF_UP|IFF_RUNNING)) - return 0; + if (strcmp(name, ifa->ifa_name) == 0 && + (ifa->ifa_flags & IFF_LOOPBACK) == 0 && + (ifa->ifa_flags & IFF_POINTOPOINT) == 0 && + ifa->ifa_addr->sa_family == AF_LINK) + break; + } + if (ifa == NULL || + (ifa->ifa_flags & IFF_UP) == 0 || + (ifa->ifa_flags & IFF_RUNNING) == 0) { + ret = 0; + } else { ifdata = ifa->ifa_data; - - return LINK_STATE_IS_UP(ifdata->ifi_link_state); + ret = LINK_STATE_IS_UP(ifdata->ifi_link_state); } - return 0; + freeifaddrs(ifap); + return ret; } void |