[glib] gmain: Unref child sources when finalising a GSource



commit 1c6df7aaeb52672c7a63517c4df271db7727b8be
Author: Philip Withnall <philip withnall collabora co uk>
Date:   Thu Sep 25 09:51:25 2014 +0100

    gmain: Unref child sources when finalising a GSource
    
    If a GSource is created, *not* attached to a GMainContext, and then has
    child sources added, dropping the last reference to the parent GSource
    will leak its references to its child sources. Currently, child sources
    are only unreffed when g_source_destroy() is called on the parent.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=737338

 glib/gmain.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
---
diff --git a/glib/gmain.c b/glib/gmain.c
index 71c816b..47e7749 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -2026,6 +2026,17 @@ g_source_unref_internal (GSource      *source,
 
       g_slist_free_full (source->priv->fds, g_free);
 
+      while (source->priv->child_sources)
+        {
+          GSource *child_source = source->priv->child_sources->data;
+
+          source->priv->child_sources =
+            g_slist_remove (source->priv->child_sources, child_source);
+          child_source->priv->parent_source = NULL;
+
+          g_source_unref_internal (child_source, context, have_lock);
+        }
+
       g_slice_free (GSourcePrivate, source->priv);
       source->priv = NULL;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]