]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
GuestInfo: fix memory leak in GuestInfoGetPrimaryIP()
authorOliver Kurth <okurth@vmware.com>
Sun, 21 Jul 2019 00:03:42 +0000 (17:03 -0700)
committerOliver Kurth <okurth@vmware.com>
Sun, 21 Jul 2019 00:03:42 +0000 (17:03 -0700)
"ipstr" was not free'ed when it was not being used.

open-vm-tools/lib/nicInfo/nicInfoPosix.c

index 1e0fee3f30973bcdb80eceee44e2cbf2006dac5c..24983fe3daa66735ef120ddd3c8cf9c59fe39f63 100644 (file)
@@ -499,7 +499,6 @@ GuestInfoGetPrimaryIP(void)
 {
    struct ifaddrs *ifaces;
    struct ifaddrs *curr;
-   char *ipstr = NULL;
    char *currIpstr = NULL;
    NicInfoPriority currPri = NICINFO_PRIORITY_MAX;
 
@@ -508,7 +507,7 @@ GuestInfoGetPrimaryIP(void)
     * to traverse and places a pointer to it in ifaces.
     */
    if (getifaddrs(&ifaces) < 0) {
-      return ipstr;
+      return NULL;
    }
 
    /*
@@ -517,6 +516,7 @@ GuestInfoGetPrimaryIP(void)
     * the first non-loopback, internet interface in the interface list.
     */
    for (curr = ifaces; curr != NULL; curr = curr->ifa_next) {
+      char *ipstr = NULL;
       int currFamily;
 
       /*
@@ -542,13 +542,15 @@ GuestInfoGetPrimaryIP(void)
          if (pri < currPri) {
             g_debug("%s: ifa_name=%s, pri=%d, currPri=%d, ipstr=%s",
                     __FUNCTION__, curr->ifa_name, pri, currPri, ipstr);
-            g_free(currIpstr);
+            free(currIpstr);
             currIpstr = ipstr;
             currPri = pri;
             if (pri == NICINFO_PRIORITY_PRIMARY) {
                /* not going to find anything better than that */
                break;
             }
+         } else {
+            free(ipstr);
          }
       }
    }