From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoAw8-0000fj-Dh for qemu-devel@nongnu.org; Thu, 07 Apr 2016 10:29:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aoAw4-0002zQ-CF for qemu-devel@nongnu.org; Thu, 07 Apr 2016 10:29:32 -0400 Received: from e31.co.us.ibm.com ([32.97.110.149]:38229) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoAw4-0002z5-13 for qemu-devel@nongnu.org; Thu, 07 Apr 2016 10:29:28 -0400 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 7 Apr 2016 08:29:26 -0600 Received: from b01cxnp22033.gho.pok.ibm.com (b01cxnp22033.gho.pok.ibm.com [9.57.198.23]) by d03dlp01.boulder.ibm.com (Postfix) with ESMTP id 37324C40009 for ; Thu, 7 Apr 2016 08:17:31 -0600 (MDT) Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u37ETMiq36044978 for ; Thu, 7 Apr 2016 14:29:22 GMT Received: from d01av01.pok.ibm.com (localhost [127.0.0.1]) by d01av01.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u37ETMRN008532 for ; Thu, 7 Apr 2016 10:29:22 -0400 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Roth References: <1459921411-20723-1-git-send-email-den@openvz.org> <1459921411-20723-2-git-send-email-den@openvz.org> <20160406235350.14380.72767@loki> <570642E5.2020609@virtuozzo.com> In-Reply-To: <570642E5.2020609@virtuozzo.com> Message-ID: <20160407142628.14380.86488@loki> Date: Thu, 07 Apr 2016 09:26:28 -0500 Subject: Re: [Qemu-devel] [PATCH 1/2] qga: fix fd leak with guest-exec i/o channels List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Yuriy Pudgorodskiy , "Denis V. Lunev" , qemu-devel@nongnu.org Quoting Yuriy Pudgorodskiy (2016-04-07 06:22:13) > On 4/7/2016 2:53 AM, Michael Roth wrote: > > Quoting Denis V. Lunev (2016-04-06 00:43:30) > >> From: Yuriy Pudgorodskiy > >> > >> Signed-off-by: Yuriy Pudgorodskiy > >> Signed-off-by: Denis V. Lunev > >> CC: Michael Roth > >> --- > >> qga/commands.c | 3 +++ > >> 1 file changed, 3 insertions(+) > >> > >> diff --git a/qga/commands.c b/qga/commands.c > >> index e091ee1..9ad2f7d 100644 > >> --- a/qga/commands.c > >> +++ b/qga/commands.c > >> @@ -446,6 +446,7 @@ GuestExec *qmp_guest_exec(const char *path, > >> g_io_channel_set_encoding(in_ch, NULL, NULL); > >> g_io_channel_set_buffered(in_ch, false); > >> g_io_channel_set_flags(in_ch, G_IO_FLAG_NONBLOCK, NULL); > >> + g_io_channel_set_close_on_unref(in_ch, true); > >> g_io_add_watch(in_ch, G_IO_OUT, guest_exec_input_watch, &gei= ->in); > >> } > >> > >> @@ -461,6 +462,8 @@ GuestExec *qmp_guest_exec(const char *path, > >> g_io_channel_set_encoding(err_ch, NULL, NULL); > >> g_io_channel_set_buffered(out_ch, false); > >> g_io_channel_set_buffered(err_ch, false); > >> + g_io_channel_set_close_on_unref(out_ch, true); > >> + g_io_channel_set_close_on_unref(err_ch, true); > > I don't seem any harm in adding these for safety, but don't the handles > > get closed via the g_io_channel_shutdown(ch, ...) calls we make prior to > > unref in guest_exec_{output,input}_watch()? Or is there another unref > > path I'm missing? > > > = > Well, it may be fixed with explicit g_io_channel_shutdown(), and may be = > it is a > better fix style, but it needs to be fixed somehow. We missed in our = > code a call > to shutdown in guest_exec_output_watch(): > = > = > diff --git a/qga/commands.c b/qga/commands.c > index 45688c8..9acb2f6 100644 > --- a/qga/commands.c > +++ b/qga/commands.c > @@ -373,6 +373,7 @@ static gboolean guest_exec_output_watch(GIOChannel *c= h, > return true; > = > close: > + g_io_channel_shutdown(ch, true, NULL); > g_io_channel_unref(ch); > g_atomic_int_set(&p->closed, 1); > return false; When I scanned the code I could've sworn I saw it for both input/output, but you're right, it's missing for output. I might squash in the above hunk for symmetry and to avoid confusion about whether it needs to be added later, but for now I've applied it as-is. > = > = > = > >> g_io_add_watch(out_ch, G_IO_IN | G_IO_HUP, > >> guest_exec_output_watch, &gei->out); > >> g_io_add_watch(err_ch, G_IO_IN | G_IO_HUP, > >> -- = > >> 2.1.4 > >> > > . > > >=20