diff options
author | Basil Salman <basil@daynix.com> | 2021-07-12 11:24:44 -0500 |
---|---|---|
committer | Michael Roth <michael.roth@amd.com> | 2021-08-02 22:11:45 -0500 |
commit | ce72f11274f6499b44aa7f2f214f6e7fc09bd9d2 (patch) | |
tree | 86e8cc123b5f1f05ebf920f1fb9b60d55561580c /qga | |
parent | 02ac3f4b959546ad69287aae84e2d52e21aeb479 (diff) |
qga-win: Fix handle leak in ga_get_win_product_name()
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>
Diffstat (limited to 'qga')
-rw-r--r-- | qga/commands-win32.c | 9 |
1 files 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; } |