Skip to contentSkip to conversation

qga-win: fix leaks of build_guest_disk_info()

PATCH Applied Marc-André Lureau 3 participants 3 messages Nov 3, 2018 – Nov 9, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qga-win: fix leaks of build_guest_disk_info()

Introduced in commit b1ba8890e63ce9432c41c5c3fc229f54c87c9c99, vol_h handle should be closed, and "out" cleanup should be done after DeviceIoControl() fails.

---
 qga/commands-win32.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
qga/commands-win32.c +4 -1
index ef1d7d48d2..62e1b51dfe 100644
@@ -797,7 +797,7 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
                     0, extents, size, NULL, NULL)) {
                 error_setg_win32(errp, GetLastError(),
                     "failed to get disk extents");
-                return NULL;
+                goto out;
             }
         } else if (last_err == ERROR_INVALID_FUNCTION) {
             /* Possibly CD-ROM or a shared drive. Try to pass the volume */
@@ -855,6 +855,9 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
 
 
 out:
+    if (vol_h != INVALID_HANDLE_VALUE) {
+        CloseHandle(vol_h);
+    }
     qapi_free_GuestDiskAddress(disk);
     g_free(extents);
     g_free(name);
Signature · 1 line
2.19.1.708.g4ede3d42df
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Marc-André Lureau

Introduced in commit b1ba8890e63ce9432c41c5c3fc229f54c87c9c99, vol_h handle should be closed, and "out" cleanup should be done after DeviceIoControl() fails.

Quoted 28 lines
---
  qga/commands-win32.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
qga/commands-win32.c +4 -1
index ef1d7d48d2..62e1b51dfe 100644
@@ -797,7 +797,7 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
                      0, extents, size, NULL, NULL)) {
                  error_setg_win32(errp, GetLastError(),
                      "failed to get disk extents");
-                return NULL;
+                goto out;
              }
          } else if (last_err == ERROR_INVALID_FUNCTION) {
              /* Possibly CD-ROM or a shared drive. Try to pass the volume */
@@ -855,6 +855,9 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
 
 
  out:
+    if (vol_h != INVALID_HANDLE_VALUE) {
+        CloseHandle(vol_h);
+    }
      qapi_free_GuestDiskAddress(disk);
      g_free(extents);
      g_free(name);
Applied
#2 lore raw
In reply to Marc-André Lureau

Quoting Marc-André Lureau (2018-11-03 08:01:43)

Quoted 5 lines

Introduced in commit b1ba8890e63ce9432c41c5c3fc229f54c87c9c99, vol_h handle should be closed, and "out" cleanup should be done after DeviceIoControl() fails.

Thanks, applied to qga tree:
https://github.com/mdroth/qemu/commits/qga

Quoted 30 lines
---
 qga/commands-win32.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
qga/commands-win32.c +4 -1
index ef1d7d48d2..62e1b51dfe 100644
@@ -797,7 +797,7 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
                     0, extents, size, NULL, NULL)) {
                 error_setg_win32(errp, GetLastError(),
                     "failed to get disk extents");
-                return NULL;
+                goto out;
             }
         } else if (last_err == ERROR_INVALID_FUNCTION) {
             /* Possibly CD-ROM or a shared drive. Try to pass the volume */
@@ -855,6 +855,9 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
 
 
 out:
+    if (vol_h != INVALID_HANDLE_VALUE) {
+        CloseHandle(vol_h);
+    }
     qapi_free_GuestDiskAddress(disk);
     g_free(extents);
     g_free(name);
Signature · 1 line
2.19.1.708.g4ede3d42df