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