diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2017-08-30 18:06:11 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2017-08-30 18:06:11 +0000 |
commit | ffe5ad1155dc407454557005e4d74fc090c28eb6 (patch) | |
tree | ed759d9b45b88aab6b2731cf964fe60d054a9440 /sbin/dhclient | |
parent | 446b827d0ab4bd81bcfc1d284afe138a6c00a628 (diff) |
Refactor interface_status() to call freeifaddrs()
before returning, plugging a memory leak.
Problem reported by Kamil Shakirov via bugs@.
tweaks, testing & ok jca@
Diffstat (limited to 'sbin/dhclient')
-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 |