qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Basil Salman <basil@daynix.com>
To: qemu-devel@nongnu.org, Michael Roth <michael.roth@amd.com>
Cc: Yan Vugenfirer <yan@daynix.com>,
	Kostiantyn Kostiuk <konstantin@daynix.com>
Subject: [PATCH 3/3] qga-win: Fix handle leak in ga_get_win_product_name()
Date: Mon,  5 Apr 2021 16:14:20 +0300	[thread overview]
Message-ID: <20210405131420.598273-3-basil@daynix.com> (raw)
In-Reply-To: <20210405131420.598273-1-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>
---
 qga/commands-win32.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index d51833ef15..8cea3ec0f8 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -2229,7 +2229,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;
@@ -2239,7 +2239,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,
@@ -2260,9 +2261,12 @@ 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.17.2



  parent reply	other threads:[~2021-04-05 13:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-05 13:14 [PATCH 1/3] qga-win: Increase VSS freeze timeout to 60 secs instead of 10 Basil Salman
2021-04-05 13:14 ` [PATCH 2/3] qga-win: Fix build_guest_fsinfo() close of nonexistent handle Basil Salman
2021-04-05 13:14 ` Basil Salman [this message]
2021-04-22  7:43 ` [PATCH 1/3] qga-win: Increase VSS freeze timeout to 60 secs instead of 10 Konstantin Kostiuk
2021-04-29  8:51   ` Konstantin Kostiuk
2021-07-13 18:40   ` Michael Roth
2021-07-14  6:17     ` Konstantin Kostiuk
2021-07-28  7:53       ` Konstantin Kostiuk
2021-05-28 11:21 ` Konstantin Kostiuk
2021-06-11  6:56 ` Konstantin Kostiuk
2021-07-04  5:52 ` Konstantin Kostiuk
2021-07-11 17:18   ` Konstantin Kostiuk

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=20210405131420.598273-3-basil@daynix.com \
    --to=basil@daynix.com \
    --cc=konstantin@daynix.com \
    --cc=michael.roth@amd.com \
    --cc=qemu-devel@nongnu.org \
    --cc=yan@daynix.com \
    /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).