From 1e5e3b64a8f3caa4c42a49b17b89dbbede892a90 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Sat, 9 Nov 2013 08:51:41 +0100 Subject: [PATCH] gsubprocess: Fix a number of leaks and a segfault Fixed a number of leaks in gsubprocess, as well as a segfault that was hidden by never calling g_subprocess_communicate_state_free(). https://bugzilla.gnome.org/show_bug.cgi?id=711803 --- gio/gsubprocess.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gio/gsubprocess.c b/gio/gsubprocess.c index cafbcbb50..ca9b00607 100644 --- a/gio/gsubprocess.c +++ b/gio/gsubprocess.c @@ -405,6 +405,7 @@ g_subprocess_exited (GPid pid, while (tasks) { g_task_return_boolean (tasks->data, TRUE); + g_object_unref (tasks->data); tasks = g_slist_delete_link (tasks, tasks); } @@ -597,7 +598,7 @@ g_subprocess_finalize (GObject *object) g_clear_object (&self->stdin_pipe); g_clear_object (&self->stdout_pipe); g_clear_object (&self->stderr_pipe); - g_free (self->argv); + g_strfreev (self->argv); G_OBJECT_CLASS (g_subprocess_parent_class)->finalize (object); } @@ -1467,13 +1468,17 @@ g_subprocess_communicate_state_free (gpointer data) { CommunicateState *state = data; + g_clear_object (&state->cancellable); g_clear_object (&state->stdin_buf); g_clear_object (&state->stdout_buf); g_clear_object (&state->stderr_buf); - if (!g_source_is_destroyed (state->cancellable_source)) - g_source_destroy (state->cancellable_source); - g_source_unref (state->cancellable_source); + if (state->cancellable_source) + { + if (!g_source_is_destroyed (state->cancellable_source)) + g_source_destroy (state->cancellable_source); + g_source_unref (state->cancellable_source); + } g_slice_free (CommunicateState, state); } @@ -1539,6 +1544,7 @@ g_subprocess_communicate_internal (GSubprocess *subprocess, g_subprocess_communicate_made_progress, g_object_ref (task)); state->outstanding_ops++; + g_object_unref (task); return state; }