[libgsf] OpenPkg: plug leaks.



commit aef504fdf4a4246fd830a48eda16b904aadeac95
Author: Morten Welinder <terra gnome org>
Date:   Sun Feb 8 15:26:08 2015 -0500

    OpenPkg: plug leaks.
    
    We hold a ref to the children and they hold a ref to us.  Something must
    be done to break that cycle.  For now, release the children when we are
    closed.

 ChangeLog                |    5 +++++
 NEWS                     |    1 +
 gsf/gsf-open-pkg-utils.c |   19 +++++++++++++------
 3 files changed, 19 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ce617f9..afa69f7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-02-08  Morten Welinder  <terra gnome org>
+
+       * gsf/gsf-open-pkg-utils.c (gsf_outfile_open_pkg_close): Plug
+       leak.
+
 2015-02-06  Morten Welinder  <terra gnome org>
 
        * gsf/gsf-open-pkg-utils.c (gsf_outfile_open_pkg_close): Also add
diff --git a/NEWS b/NEWS
index 126aeb4..72a207f 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ libgsf 1.14.32
 Morten:
        * Fix obscure problem with xml parser.
        * Add vml to openpkg utils.
+       * Plug leak.
 
 --------------------------------------------------------------------------
 libgsf 1.14.31
diff --git a/gsf/gsf-open-pkg-utils.c b/gsf/gsf-open-pkg-utils.c
index d28be46..09eed7d 100644
--- a/gsf/gsf-open-pkg-utils.c
+++ b/gsf/gsf-open-pkg-utils.c
@@ -544,7 +544,6 @@ static void
 gsf_outfile_open_pkg_finalize (GObject *obj)
 {
        GsfOutfileOpenPkg *open_pkg = GSF_OUTFILE_OPEN_PKG (obj);
-       GSList *ptr;
 
        if (open_pkg->sink != NULL) {
                g_object_unref (open_pkg->sink);
@@ -553,9 +552,9 @@ gsf_outfile_open_pkg_finalize (GObject *obj)
        g_free (open_pkg->content_type);
        open_pkg->content_type = NULL;
 
-       for (ptr = open_pkg->children ; ptr != NULL ; ptr = ptr->next)
-               g_object_unref (ptr->data);
-       g_slist_free (open_pkg->children);
+       g_slist_free_full (open_pkg->children, g_object_unref);
+       open_pkg->children = NULL;
+
        parent_class->finalize (obj);
 }
 
@@ -592,8 +591,11 @@ gsf_outfile_open_pkg_new_child (GsfOutfile *parent,
        gsf_outfile_open_pkg_set_sink (child, sink);
        g_object_unref (sink);
 
-       open_pkg->children = g_slist_prepend (open_pkg->children, child);
-       g_object_ref (child);
+       /*
+        * Holding a ref here is not ideal.  It means we won't release any of the
+        * children until the package is closed.
+        */
+       open_pkg->children = g_slist_prepend (open_pkg->children, g_object_ref (child));
 
        return GSF_OUTPUT (child);
 }
@@ -720,6 +722,11 @@ gsf_outfile_open_pkg_close (GsfOutput *output)
        /* close the container */
        if (NULL == gsf_output_name (output))
                return gsf_output_close (open_pkg->sink);
+
+       /* Dispose of children here to break link cycles.  */
+       g_slist_free_full (open_pkg->children, g_object_unref);
+       open_pkg->children = NULL;
+
        return res;
 }
 


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