]> git.sur5r.net Git - i3/i3status/commitdiff
Free the addresses correctly
authorMichael Stapelberg <michael@stapelberg.de>
Wed, 22 Jul 2009 16:30:16 +0000 (18:30 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 22 Jul 2009 16:30:16 +0000 (18:30 +0200)
src/get_ip_addr.c

index 354ae08696f33768825e01c5c1bdad9cf9fa1119..cc812f2e8b1869e85246775b9d30b28df2485ca6 100644 (file)
@@ -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;
 }