From: Gonglei Date: Mon, 19 May 2014 07:26:03 +0000 (+0800) Subject: qga: Fix handle fd leak in acquire_privilege() X-Git-Tag: qemu-xen-4.5.0-rc1^2~50 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=ba980a52d65a2eb20aba22a7cd3cd9de1fc9cbdc;p=qemu-upstream-4.6-testing.git qga: Fix handle fd leak in acquire_privilege() token should be closed in all conditions. So move CloseHandle(token) to "out" branch. Signed-off-by: Wang Rui Signed-off-by: Gonglei Signed-off-by: Michael Roth (cherry picked from commit 374044f08fe18a18469b981812cd8695f5b3569c) Signed-off-by: Michael Roth --- diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 0ee07b6e2..26ef1721d 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -31,7 +31,7 @@ static void acquire_privilege(const char *name, Error **err) { - HANDLE token; + HANDLE token = NULL; TOKEN_PRIVILEGES priv; Error *local_err = NULL; @@ -57,13 +57,15 @@ static void acquire_privilege(const char *name, Error **err) goto out; } - CloseHandle(token); } else { error_set(&local_err, QERR_QGA_COMMAND_FAILED, "failed to open privilege token"); } out: + if (token) { + CloseHandle(token); + } if (local_err) { error_propagate(err, local_err); }