From: Michael Roth <michael.roth@amd.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, Basil Salman <basil@daynix.com>,
Basil Salman <bsalman@redhat.com>
Subject: [PULL for-6.1 3/6] qga-win: Fix handle leak in ga_get_win_product_name()
Date: Tue, 3 Aug 2021 08:24:49 -0500 [thread overview]
Message-ID: <20210803132450.1093602-4-michael.roth@amd.com> (raw)
In-Reply-To: <20210803132450.1093602-1-michael.roth@amd.com>
From: Basil Salman <basil@daynix.com>
In ga_get_win_product_name() a handle to Registry key was open but not
closed.
In this patch the handle is closed as part of the free routine.
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1929144
Signed-off-by: Basil Salman <basil@daynix.com>
Signed-off-by: Basil Salman <bsalman@redhat.com>
Signed-off-by: Michael Roth <michael.roth@amd.com>
---
qga/commands-win32.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 763186efd4..098211e724 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -2231,7 +2231,7 @@ static char *ga_get_win_name(OSVERSIONINFOEXW const *os_version, bool id)
static char *ga_get_win_product_name(Error **errp)
{
- HKEY key = NULL;
+ HKEY key = INVALID_HANDLE_VALUE;
DWORD size = 128;
char *result = g_malloc0(size);
LONG err = ERROR_SUCCESS;
@@ -2241,7 +2241,8 @@ static char *ga_get_win_product_name(Error **errp)
&key);
if (err != ERROR_SUCCESS) {
error_setg_win32(errp, err, "failed to open registry key");
- goto fail;
+ g_free(result);
+ return NULL;
}
err = RegQueryValueExA(key, "ProductName", NULL, NULL,
@@ -2262,9 +2263,13 @@ static char *ga_get_win_product_name(Error **errp)
goto fail;
}
+ RegCloseKey(key);
return result;
fail:
+ if (key != INVALID_HANDLE_VALUE) {
+ RegCloseKey(key);
+ }
g_free(result);
return NULL;
}
--
2.25.1
next prev parent reply other threads:[~2021-08-03 13:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-03 13:24 [PULL for-6.1 0/6] qemu-ga patch queue for hard-freeze Michael Roth
2021-08-03 13:24 ` [PULL for-6.1 1/6] qga-win: Increase VSS freeze timeout to 60 secs instead of 10 Michael Roth
2021-08-03 13:24 ` [PULL for-6.1 2/6] qga-win: Fix build_guest_fsinfo() close of nonexistent Michael Roth
2021-08-03 13:24 ` Michael Roth [this message]
2021-08-03 13:24 ` [PULL for-6.1 4/6] qga-win: Free GMatchInfo properly Michael Roth
2021-08-03 13:24 ` [PULL for-6.1 5/6] qemu-ga/msi: fix w32 libgcc name Michael Roth
2021-08-03 13:24 ` [PULL for-6.1 6/6] qga-win/msi: fix missing libstdc++-6 DLL in MSI installer Michael Roth
2021-08-03 16:49 ` [PULL for-6.1 0/6] qemu-ga patch queue for hard-freeze Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210803132450.1093602-4-michael.roth@amd.com \
--to=michael.roth@amd.com \
--cc=basil@daynix.com \
--cc=bsalman@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).