From f898ee0f9951f2875c6cea299b4a1287e0a90e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Sat, 3 Nov 2018 17:01:43 +0400 Subject: [PATCH 1/2] qga-win: fix leaks of build_guest_disk_info() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduced in commit b1ba8890e63ce9432c41c5c3fc229f54c87c9c99, vol_h handle should be closed, and "out" cleanup should be done after DeviceIoControl() fails. Signed-off-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Michael Roth --- qga/commands-win32.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index ef1d7d48d2..62e1b51dfe 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -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); From 61baac2fdb7ad3891fb00bbd3c9e8b8ca87f0f62 Mon Sep 17 00:00:00 2001 From: Peter Maydell Date: Thu, 8 Nov 2018 12:52:23 +0000 Subject: [PATCH 2/2] qga: Add multiple include guard to guest-agent-core.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The guest-agent-core.h header was missing the usual guards against multiple inclusion; add them. (Spotted by lgtm.com's static analyzer.) Signed-off-by: Peter Maydell Reviewed-by: Marc-André Lureau Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Signed-off-by: Michael Roth --- qga/guest-agent-core.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qga/guest-agent-core.h b/qga/guest-agent-core.h index 6f4d214cb9..60eae16f27 100644 --- a/qga/guest-agent-core.h +++ b/qga/guest-agent-core.h @@ -10,6 +10,9 @@ * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. */ +#ifndef GUEST_AGENT_CORE_H +#define GUEST_AGENT_CORE_H + #include "qapi/qmp/dispatch.h" #include "qemu-common.h" #include "qga-qapi-types.h" @@ -46,3 +49,5 @@ int ga_parse_whence(GuestFileWhence *whence, Error **errp); #ifndef _WIN32 void reopen_fd_to_null(int fd); #endif + +#endif /* GUEST_AGENT_CORE_H */