[gnumeric] xml: leak fixes.



commit 99069f97d406d8171b6666251541d672b424cda6
Author: Morten Welinder <terra gnome org>
Date:   Tue Feb 17 15:11:38 2015 -0500

    xml: leak fixes.

 src/gnm-so-filled.c      |    5 ++++-
 src/gnm-so-line.c        |    5 ++++-
 src/gnm-so-path.c        |    5 ++++-
 src/gutils.c             |   21 +++++++++++++++++++++
 src/gutils.h             |    2 ++
 src/sheet-object-graph.c |    5 ++++-
 src/sheet-object-image.c |    5 ++++-
 src/xml-sax-read.c       |    4 +++-
 8 files changed, 46 insertions(+), 6 deletions(-)
---
diff --git a/src/gnm-so-filled.c b/src/gnm-so-filled.c
index e133852..6c7e940 100644
--- a/src/gnm-so-filled.c
+++ b/src/gnm-so-filled.c
@@ -27,6 +27,7 @@
 #include "gnm-so-filled.h"
 #include "sheet-object-impl.h"
 #include "sheet.h"
+#include "gutils.h"
 #include "xml-sax.h"
 
 #include <goffice/goffice.h>
@@ -370,8 +371,10 @@ gnm_so_filled_prep_sax_parser (SheetObject *so, GsfXMLIn *xin,
        double tmp;
        int type;
 
-       if (NULL == doc)
+       if (NULL == doc) {
                doc = gsf_xml_in_doc_new (dtd, NULL);
+               gnm_xml_in_doc_dispose_on_exit (&doc);
+       }
        gsf_xml_in_push_state (xin, doc, NULL, NULL, attrs);
 
        for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
diff --git a/src/gnm-so-line.c b/src/gnm-so-line.c
index 820f3f4..def4c60 100644
--- a/src/gnm-so-line.c
+++ b/src/gnm-so-line.c
@@ -25,6 +25,7 @@
 #include "gnumeric.h"
 #include "gnm-so-line.h"
 #include "sheet-object-impl.h"
+#include "gutils.h"
 #include "xml-sax.h"
 
 #include <goffice/goffice.h>
@@ -304,8 +305,10 @@ gnm_so_line_prep_sax_parser (SheetObject *so, GsfXMLIn *xin,
        double tmp, arrow_a = -1., arrow_b = -1., arrow_c = -1.;
        int type = 0;
 
-       if (NULL == doc)
+       if (NULL == doc) {
                doc = gsf_xml_in_doc_new (dtd, NULL);
+               gnm_xml_in_doc_dispose_on_exit (&doc);
+       }
        gsf_xml_in_push_state (xin, doc, NULL, NULL, attrs);
 
        go_arrow_clear (&sol->start_arrow);
diff --git a/src/gnm-so-path.c b/src/gnm-so-path.c
index a6682a3..0125546 100644
--- a/src/gnm-so-path.c
+++ b/src/gnm-so-path.c
@@ -26,6 +26,7 @@
 #include "gnm-so-path.h"
 #include "sheet-object-impl.h"
 #include "sheet.h"
+#include "gutils.h"
 #include "xml-sax.h"
 
 #include <goffice/goffice.h>
@@ -439,8 +440,10 @@ gnm_so_path_prep_sax_parser (SheetObject *so, GsfXMLIn *xin,
        static GsfXMLInDoc *doc = NULL;
        GnmSOPath *sop = GNM_SO_PATH(so);
 
-       if (NULL == doc)
+       if (NULL == doc) {
                doc = gsf_xml_in_doc_new (dtd, NULL);
+               gnm_xml_in_doc_dispose_on_exit (&doc);
+       }
        gsf_xml_in_push_state (xin, doc, NULL, NULL, attrs);
 
        for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
diff --git a/src/gutils.c b/src/gutils.c
index 046711d..cfdc059 100644
--- a/src/gutils.c
+++ b/src/gutils.c
@@ -37,6 +37,7 @@ static char *gnumeric_locale_dir;
 static char *gnumeric_usr_dir;
 static char *gnumeric_usr_dir_unversioned;
 static char *gnumeric_extern_plugin_dir;
+static GSList *gutils_xml_in_docs;
 
 static gboolean
 running_in_tree (void)
@@ -118,6 +119,8 @@ gutils_init (void)
 void
 gutils_shutdown (void)
 {
+       GSList *l;
+
        g_free (gnumeric_lib_dir);
        gnumeric_lib_dir = NULL;
        g_free (gnumeric_data_dir);
@@ -130,6 +133,14 @@ gutils_shutdown (void)
        gnumeric_usr_dir_unversioned = NULL;
        g_free (gnumeric_extern_plugin_dir);
        gnumeric_extern_plugin_dir = NULL;
+
+       for (l = gutils_xml_in_docs; l; l = l->next) {
+               GsfXMLInDoc **pdoc = l->data;
+               gsf_xml_in_doc_free (*pdoc);
+               *pdoc = NULL;
+       }
+       g_slist_free (gutils_xml_in_docs);
+       gutils_xml_in_docs = NULL;
 }
 
 char const *
@@ -792,3 +803,13 @@ gnm_hash_table_foreach_ordered (GHashTable *h,
        /* Clean up */
        g_ptr_array_free (data, TRUE);
 }
+
+/* ------------------------------------------------------------------------- */
+
+void
+gnm_xml_in_doc_dispose_on_exit (GsfXMLInDoc **pdoc)
+{
+       gutils_xml_in_docs = g_slist_prepend (gutils_xml_in_docs, pdoc);
+}
+
+/* ------------------------------------------------------------------------- */
diff --git a/src/gutils.h b/src/gutils.h
index 12830b4..658e2ee 100644
--- a/src/gutils.h
+++ b/src/gutils.h
@@ -60,6 +60,8 @@ void gnm_hash_table_foreach_ordered (GHashTable *h,
                                     GnmHashTableOrder order,
                                     gpointer user);
 
+void gnm_xml_in_doc_dispose_on_exit (GsfXMLInDoc **pdoc);
+
 G_END_DECLS
 
 #endif /* _GNM_GUTILS_H_ */
diff --git a/src/sheet-object-graph.c b/src/sheet-object-graph.c
index ff11a16..d7bcc7a 100644
--- a/src/sheet-object-graph.c
+++ b/src/sheet-object-graph.c
@@ -39,6 +39,7 @@
 #include "print-info.h"
 #include "workbook.h"
 #include "workbook-view.h"
+#include "gutils.h"
 #include <graph.h>
 
 #include <goffice/goffice.h>
@@ -1097,8 +1098,10 @@ gnm_sogg_prep_sax_parser (SheetObject *so, GsfXMLIn *xin, xmlChar const **attrs,
        GuppiReadState *state;
        GogTheme *theme = gog_theme_registry_lookup ("Guppi");
 
-       if (NULL == doc)
+       if (NULL == doc) {
                doc = gsf_xml_in_doc_new (dtd, NULL);
+               gnm_xml_in_doc_dispose_on_exit (&doc);
+       }
        state = g_new0 (GuppiReadState, 1);
        state->graph = g_object_new (GOG_TYPE_GRAPH, NULL);
        gog_graph_set_theme (state->graph, theme);
diff --git a/src/sheet-object-image.c b/src/sheet-object-image.c
index 9067d32..13e0488 100644
--- a/src/sheet-object-image.c
+++ b/src/sheet-object-image.c
@@ -18,6 +18,7 @@
 #include "sheet-control-gui.h"
 #include "gui-file.h"
 #include "application.h"
+#include "gutils.h"
 #include "xml-sax.h"
 
 #include <goffice/goffice.h>
@@ -413,8 +414,10 @@ gnm_soi_prep_sax_parser (SheetObject *so, GsfXMLIn *xin,
        static GsfXMLInDoc *doc = NULL;
        SheetObjectImage *soi = SHEET_OBJECT_IMAGE (so);
 
-       if (NULL == doc)
+       if (NULL == doc) {
                doc = gsf_xml_in_doc_new (dtd, NULL);
+               gnm_xml_in_doc_dispose_on_exit (&doc);
+       }
        gsf_xml_in_push_state (xin, doc, NULL, NULL, attrs);
 
        for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) {
diff --git a/src/xml-sax-read.c b/src/xml-sax-read.c
index fe5b583..ab8eacc 100644
--- a/src/xml-sax-read.c
+++ b/src/xml-sax-read.c
@@ -2409,8 +2409,10 @@ xml_sax_read_obj (GsfXMLIn *xin, gboolean needs_cleanup,
                  GSF_XML_IN_NODE_END
                };
                static GsfXMLInDoc *doc = NULL;
-               if (NULL == doc)
+               if (NULL == doc) {
                        doc = gsf_xml_in_doc_new (dtd, NULL);
+                       gnm_xml_in_doc_dispose_on_exit (&doc);
+               }
                gsf_xml_in_push_state (xin, doc, NULL,
                        (GsfXMLInExtDtor) gnm_xml_finish_obj, attrs);
        }


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