Blame SOURCES/0002-qga-get_pci_info-leak-fix.patch

30761c
From a956c1a2ab36a221c0a5dc7cd474ac86f4033983 Mon Sep 17 00:00:00 2001
30761c
From: Kostiantyn Kostiuk <konstantin@daynix.com>
30761c
Date: Tue, 20 Jul 2021 17:22:18 +0000
30761c
Subject: [PATCH 2/2] qga: get_pci_info leak fix
30761c
30761c
Signed-off-by: Kostiantyn Kostiuk <konstantin@daynix.com>
30761c
---
30761c
 qga/commands-win32.c | 25 +++++++++++++++++++++----
30761c
 1 file changed, 21 insertions(+), 4 deletions(-)
30761c
30761c
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
30761c
index 300b87c859..cf6d46361a 100644
30761c
--- a/qga/commands-win32.c
30761c
+++ b/qga/commands-win32.c
30761c
@@ -514,7 +514,10 @@ DEFINE_GUID(GUID_DEVINTERFACE_STORAGEPORT,
30761c
 
30761c
 static GuestPCIAddress *get_pci_info(int number, Error **errp)
30761c
 {
30761c
-    HDEVINFO dev_info;
30761c
+    HDEVINFO dev_info = INVALID_HANDLE_VALUE;
30761c
+    HDEVINFO parent_dev_info = INVALID_HANDLE_VALUE;
30761c
+    char *parent_dev_id = NULL;
30761c
+
30761c
     SP_DEVINFO_DATA dev_info_data;
30761c
     SP_DEVICE_INTERFACE_DATA dev_iface_data;
30761c
     HANDLE dev_file;
30761c
@@ -541,8 +544,6 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp)
30761c
     for (i = 0; SetupDiEnumDeviceInfo(dev_info, i, &dev_info_data); i++) {
30761c
         PSP_DEVICE_INTERFACE_DETAIL_DATA pdev_iface_detail_data = NULL;
30761c
         STORAGE_DEVICE_NUMBER sdn;
30761c
-        char *parent_dev_id = NULL;
30761c
-        HDEVINFO parent_dev_info;
30761c
         SP_DEVINFO_DATA parent_dev_info_data;
30761c
         DWORD j;
30761c
         DWORD size = 0;
30761c
@@ -657,6 +658,7 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp)
30761c
             SetupDiGetClassDevs(&GUID_DEVINTERFACE_STORAGEPORT, parent_dev_id,
30761c
                                 NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
30761c
         g_free(parent_dev_id);
30761c
+        parent_dev_id = NULL;
30761c
 
30761c
         if (parent_dev_info == INVALID_HANDLE_VALUE) {
30761c
             error_setg_win32(errp, GetLastError(),
30761c
@@ -745,12 +747,27 @@ static GuestPCIAddress *get_pci_info(int number, Error **errp)
30761c
             }
30761c
         }
30761c
         SetupDiDestroyDeviceInfoList(parent_dev_info);
30761c
+        parent_dev_info = INVALID_HANDLE_VALUE;
30761c
         break;
30761c
     }
30761c
 
30761c
 free_dev_info:
30761c
-    SetupDiDestroyDeviceInfoList(dev_info);
30761c
 out:
30761c
+    if (parent_dev_id != NULL) {
30761c
+        g_debug("get_pci_info: parent_dev_id pointer present");
30761c
+        g_free(parent_dev_id);
30761c
+    }
30761c
+
30761c
+    if (dev_info != INVALID_HANDLE_VALUE) {
30761c
+        g_debug("get_pci_info: dev_info handle present");
30761c
+        SetupDiDestroyDeviceInfoList(dev_info);
30761c
+    }
30761c
+
30761c
+    if (parent_dev_info != INVALID_HANDLE_VALUE) {
30761c
+        g_debug("get_pci_info: parent_dev_info handle present");
30761c
+        SetupDiDestroyDeviceInfoList(parent_dev_info);
30761c
+    }
30761c
+
30761c
     return pci;
30761c
 }
30761c
 
30761c
-- 
30761c
2.25.1
30761c