From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wmq0C-0002LF-Rk for qemu-devel@nongnu.org; Tue, 20 May 2014 15:47:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wmq05-0003Kt-6K for qemu-devel@nongnu.org; Tue, 20 May 2014 15:47:08 -0400 Received: from e34.co.us.ibm.com ([32.97.110.152]:50636) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wmq04-0003Kk-Tu for qemu-devel@nongnu.org; Tue, 20 May 2014 15:47:01 -0400 Received: from /spool/local by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 20 May 2014 13:46:59 -0600 Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id B51201FF003F for ; Tue, 20 May 2014 13:46:57 -0600 (MDT) Received: from d03av05.boulder.ibm.com (d03av05.boulder.ibm.com [9.17.195.85]) by b03cxnp08025.gho.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s4KJkvoC63439102 for ; Tue, 20 May 2014 21:46:57 +0200 Received: from d03av05.boulder.ibm.com (localhost [127.0.0.1]) by d03av05.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s4KJkvA9023410 for ; Tue, 20 May 2014 13:46:57 -0600 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Roth In-Reply-To: <20140520151742.6343af19@redhat.com> References: <1400484363-4744-1-git-send-email-arei.gonglei@huawei.com> <20140520151742.6343af19@redhat.com> Message-ID: <20140520194638.2719.45727@loki> Date: Tue, 20 May 2014 14:46:38 -0500 Subject: Re: [Qemu-devel] [PATCH] qga: Fix handle fd leak in acquire_privilege() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Luiz Capitulino , Wang Rui Cc: arei.gonglei@huawei.com, qemu-devel@nongnu.org, armbru@redhat.com Quoting Luiz Capitulino (2014-05-20 14:17:42) > On Mon, 19 May 2014 15:26:03 +0800 > wrote: > = > > From: Gonglei > > = > > token should be closed in all conditions. > > So move CloseHandle(token) to "out" branch. > = > Looks good to me. Michael, are you going to pick this one? Sure I'll queue it. Though i'm a bit surprised OpenProcessToken() will still return an open handle on failure. Is there any confirmation a handle is actually getting leaked here, as opposed to just returning a handle that's already been closed? If it's the latter case we might end up closing it twice after the change, so just want to confirm. > = > > = > > Signed-off-by: Wang Rui > > Signed-off-by: Gonglei > > --- > > qga/commands-win32.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > = > > diff --git a/qga/commands-win32.c b/qga/commands-win32.c > > index d793dd0..e769396 100644 > > --- a/qga/commands-win32.c > > +++ b/qga/commands-win32.c > > @@ -31,7 +31,7 @@ > > = > > static void acquire_privilege(const char *name, Error **errp) > > { > > - HANDLE token; > > + HANDLE token =3D NULL; > > TOKEN_PRIVILEGES priv; > > Error *local_err =3D NULL; > > = > > @@ -53,13 +53,15 @@ static void acquire_privilege(const char *name, Err= or **errp) > > 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(errp, local_err); > > }