From e56213db28c442a7a67e2424d1631a7f1f42a5fc Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 22 Jul 2009 18:30:16 +0200 Subject: Free the addresses correctly --- src/get_ip_addr.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/get_ip_addr.c b/src/get_ip_addr.c index 354ae08..cc812f2 100644 --- a/src/get_ip_addr.c +++ b/src/get_ip_addr.c @@ -42,19 +42,25 @@ const char *get_ip_addr(const char *interface) { addrp = addrp->ifa_next) { /* Check if the interface is down */ if (strcmp(addrp->ifa_name, eth_interface) == 0 && - (addrp->ifa_flags & IFF_RUNNING) == 0) + (addrp->ifa_flags & IFF_RUNNING) == 0) { + freeifaddrs(ifaddr); return NULL; + } } - if (addrp == NULL) + if (addrp == NULL) { + freeifaddrs(ifaddr); return "no IP"; + } int ret; if ((ret = getnameinfo(addrp->ifa_addr, len, part, sizeof(part), NULL, 0, NI_NUMERICHOST)) != 0) { fprintf(stderr, "getnameinfo(): %s\n", gai_strerror(ret)); + freeifaddrs(ifaddr); return "no IP"; } + freeifaddrs(ifaddr); return part; } -- cgit v1.2.3