Skip to content

Commit

Permalink
qga-win: Fix handle leak in ga_get_win_product_name()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Basils authored and mdroth committed Aug 3, 2021
1 parent 02ac3f4 commit ce72f11
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions qga/commands-win32.c
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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;
}
Expand Down

0 comments on commit ce72f11

Please sign in to comment.