qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/3] qga-win: Fix build_guest_fsinfo() close of nonexistent handl


From: Basil Salman
Subject: [PATCH 2/3] qga-win: Fix build_guest_fsinfo() close of nonexistent handle
Date: Mon, 5 Apr 2021 16:14:19 +0300

On the current error path of build_guest_fsinfo(), a non existent
handle is passed to CloseHandle().
This patch add initialization of hLocalDiskHandle to INVALID_HANDLE_VALUE,
and checks for handle validity before the handle is closed.

Signed-off-by: Basil Salman <basil@daynix.com>
Signed-off-by: Basil Salman <basil@redhat.com>
---
 qga/commands-win32.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 27baf17d6c..d51833ef15 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -1091,7 +1091,7 @@ static GuestFilesystemInfo *build_guest_fsinfo(char 
*guid, Error **errp)
     size_t len;
     uint64_t i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes;
     GuestFilesystemInfo *fs = NULL;
-    HANDLE hLocalDiskHandle = NULL;
+    HANDLE hLocalDiskHandle = INVALID_HANDLE_VALUE;
 
     GetVolumePathNamesForVolumeName(guid, (LPCH)&mnt, 0, &info_size);
     if (GetLastError() != ERROR_MORE_DATA) {
@@ -1149,7 +1149,8 @@ static GuestFilesystemInfo *build_guest_fsinfo(char 
*guid, Error **errp)
     fs->type = g_strdup(fs_name);
     fs->disk = build_guest_disk_info(guid, errp);
 free:
-    CloseHandle(hLocalDiskHandle);
+    if (hLocalDiskHandle != INVALID_HANDLE_VALUE) {
+        CloseHandle(hLocalDiskHandle);
+    }
     g_free(mnt_point);
     return fs;
 }
-- 
2.17.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]