[1/2] qga: fix fd leak with guest-exec i/o channels
diff mbox

Message ID 1459921411-20723-2-git-send-email-den@openvz.org
State New
Headers show

Commit Message

Denis V. Lunev April 6, 2016, 5:43 a.m. UTC
From: Yuriy Pudgorodskiy <yur@virtuozzo.com>

Signed-off-by: Yuriy Pudgorodskiy <yur@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 qga/commands.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Michael Roth April 6, 2016, 11:53 p.m. UTC | #1
Quoting Denis V. Lunev (2016-04-06 00:43:30)
> From: Yuriy Pudgorodskiy <yur@virtuozzo.com>
> 
> Signed-off-by: Yuriy Pudgorodskiy <yur@virtuozzo.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Michael Roth <mdroth@linux.vnet.ibm.com>
> ---
>  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?

>          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
>

Patch
diff mbox

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);
         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,