From: Oliver Kurth Date: Sun, 21 Jul 2019 00:03:42 +0000 (-0700) Subject: GuestInfo: fix memory leak in GuestInfoGetPrimaryIP() X-Git-Tag: stable-11.0.0~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=003ed9e082dd10c67aa022514ad0c662c7e1a6a4;p=thirdparty%2Fopen-vm-tools.git GuestInfo: fix memory leak in GuestInfoGetPrimaryIP() "ipstr" was not free'ed when it was not being used. --- diff --git a/open-vm-tools/lib/nicInfo/nicInfoPosix.c b/open-vm-tools/lib/nicInfo/nicInfoPosix.c index 1e0fee3f3..24983fe3d 100644 --- a/open-vm-tools/lib/nicInfo/nicInfoPosix.c +++ b/open-vm-tools/lib/nicInfo/nicInfoPosix.c @@ -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); } } }