Blob Blame History Raw
From 1df114456e53479bad9ece58f2fb6602dc31b9af Mon Sep 17 00:00:00 2001
From: Cathy Avery <cavery@redhat.com>
Date: Thu, 25 Mar 2021 13:18:52 -0400
Subject: [PATCH] Fix memory leaks in guestInfo/diskInfo.c.

RH-Author: Cathy Avery <cavery@redhat.com>
RH-MergeRequest: 1: Fix memory leaks in guestInfo/diskInfo.c.
RH-Commit: [1/1] ddc8da05f5d6ae36d32b99a8100026f3ac1badbe (cavery/open-vm-tools)
RH-Bugzilla: 1937420
RH-Acked-by: Acked-by: Mohammed Gamal <mgamal@redhat.com>
RH-Acked-by: Acked-by: Vitaly Kuznetsov vkuznets@redhat.com

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

(cherry picked from commit 25c2e973583cf189995c9638701e4bef9e1c851c)
Signed-off-by: Cathy Avery <cavery@redhat.com>
---
 open-vm-tools/services/plugins/guestInfo/diskInfo.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/open-vm-tools/services/plugins/guestInfo/diskInfo.c b/open-vm-tools/services/plugins/guestInfo/diskInfo.c
index 032c0928..e63d232a 100644
--- a/open-vm-tools/services/plugins/guestInfo/diskInfo.c
+++ b/open-vm-tools/services/plugins/guestInfo/diskInfo.c
@@ -270,6 +270,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)
@@ -296,6 +297,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);
@@ -431,6 +433,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);
@@ -659,6 +662,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;
-- 
2.27.0