From: John Wolfe Date: Tue, 13 Oct 2020 21:00:59 +0000 (-0700) Subject: Fix memory leaks in guestInfo/diskInfo.c. X-Git-Tag: stable-11.2.0~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25c2e973583cf189995c9638701e4bef9e1c851c;p=thirdparty%2Fopen-vm-tools.git Fix memory leaks in guestInfo/diskInfo.c. When checking for IDE, SATA and SAS disk drives, the glib GMatchInfo is passed to a g_regex_match() function inside a for loop. It was not properly passed to g_match_info_free() before subsequently being reused. This addresses https://github.com/vmware/open-vm-tools/issues/452 --- diff --git a/open-vm-tools/services/plugins/guestInfo/diskInfo.c b/open-vm-tools/services/plugins/guestInfo/diskInfo.c index 7d68de710..f8d9e967f 100644 --- a/open-vm-tools/services/plugins/guestInfo/diskInfo.c +++ b/open-vm-tools/services/plugins/guestInfo/diskInfo.c @@ -321,6 +321,7 @@ GuestInfoGetIdeSataDev(const char *tgtHostPath, regexAtaOrHost = regexAta; } else { + g_match_info_free(matchInfo); COMP_STATIC_REGEX(regexHostPath, "^.*/host(\\d+)$", gErr, exit) if (g_regex_match(regexHostPath, realPath, 0, &matchInfo)) { COMP_STATIC_REGEX(regexHost, "^host(\\d+)$", gErr, exit) @@ -347,6 +348,7 @@ GuestInfoGetIdeSataDev(const char *tgtHostPath, for (fileNum = 0; fileNum < numFiles; fileNum++) { int currHost; + g_match_info_free(matchInfo); if (g_regex_match(regexAtaOrHost, fileNameList[fileNum], 0, &matchInfo)) { g_free(charHost); charHost = g_match_info_fetch(matchInfo, 1); @@ -482,6 +484,7 @@ GuestInfoCheckSASDevice(char *pciDevPath, pciDevPath); } for (fileNum = 0; fileNum < numFiles; fileNum++) { + g_match_info_free(matchInfo); if (g_regex_match(regexSas, fileNameList[fileNum], 0, &matchInfo)) { free(*unit); /* free previous "unit" string */ *unit = g_match_info_fetch(matchInfo, 1); @@ -712,6 +715,7 @@ GuestInfoLinuxBlockDevice(const char *startPath, /* Check for NVMe device. */ COMP_STATIC_REGEX(regexNvme, "^.*/nvme\\d+$", gErr, finished) + g_match_info_free(matchInfo); if (!g_regex_match(regexNvme, realPath, 0, &matchInfo)) { g_debug("%s: block disk device pattern not found\n", __FUNCTION__); goto finished;