[gnumeric] xlsx: plug leak.



commit 4bae3d46528cbdc4c5de1e87ea131a1904235f8c
Author: Morten Welinder <terra gnome org>
Date:   Mon Feb 2 21:58:40 2015 -0500

    xlsx: plug leak.
    
    Take care to delete dummy axis objects we create.

 plugins/excel/ChangeLog           |    1 +
 plugins/excel/xlsx-read-drawing.c |   51 ++++++++++++++++++++++++++++--------
 2 files changed, 40 insertions(+), 12 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index c96ffb2..223abf2 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,6 +1,7 @@
 2015-02-02  Morten Welinder  <terra gnome org>
 
        * xlsx-read-drawing.c (xlsx_chart_push_obj): Optionally check for leaks.
+       (xlsx_axis_end): Plug leak.
 
        * xlsx-write-drawing.c (xlsx_write_axis): Make axis visible.
 
diff --git a/plugins/excel/xlsx-read-drawing.c b/plugins/excel/xlsx-read-drawing.c
index 408370c..f2250ca 100644
--- a/plugins/excel/xlsx-read-drawing.c
+++ b/plugins/excel/xlsx-read-drawing.c
@@ -699,11 +699,19 @@ xlsx_create_axis_object (XLSXReadState *state)
        gboolean cat_or_date = (state->axis.type == XLSX_AXIS_CAT ||
                                state->axis.type == XLSX_AXIS_DATE);
        GogObject *axis;
+       gboolean dummy;
 
-       plot = state->axis.info && state->axis.info->plots
-               ? state->axis.info->plots->data /* just use the first */
-               : NULL;
-       type = plot ? G_OBJECT_TYPE_NAME (plot) : "GogLinePlot";
+       if (state->cur_obj)
+               return;
+
+       dummy = (!state->axis.info || !state->axis.info->plots);
+       if (dummy) {
+               plot = NULL;
+               type = "GogLinePlot";
+       } else {
+               plot = state->axis.info->plots->data; /* just use the first */
+               type = G_OBJECT_TYPE_NAME (plot);
+       }
 
        switch (xlsx_plottype_from_type_name (type)) {
        case XLSX_PT_GOGRADARPLOT:
@@ -731,7 +739,7 @@ xlsx_create_axis_object (XLSXReadState *state)
                role = (inverted ^ cat_or_date) ? "X-Axis" : "Y-Axis";
 
        axis = gog_object_add_by_name (GOG_OBJECT (state->chart), role, NULL);
-       state->axis.obj = g_object_ref (axis);
+       state->axis.obj = GOG_AXIS (axis);
 #ifdef DEBUG_AXIS
        g_printerr ("Created axis object %s with role %s\n",
                    gog_object_get_name (axis), role);
@@ -741,8 +749,13 @@ xlsx_create_axis_object (XLSXReadState *state)
        xlsx_chart_pop_obj (state);
        xlsx_chart_push_obj (state, axis);
 
-       if (NULL != state->axis.info) {
-               state->axis.info->axis = state->axis.obj;
+       if (dummy)
+               g_object_set (axis, "invisible", TRUE, NULL);
+
+       if (state->axis.info) {
+               if (dummy)
+                       state->axis.info->deleted = TRUE;
+               state->axis.info->axis = g_object_ref (state->axis.obj);
                g_hash_table_replace (state->axis.by_obj, axis, state->axis.info);
 
                g_object_set (G_OBJECT (state->axis.obj),
@@ -862,10 +875,10 @@ static void
 xlsx_axis_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
 {
        XLSXReadState *state = (XLSXReadState *)xin->user_state;
+       GogAxis *axis = state->axis.obj;
 
-       if (NULL != state->axis.info) {
+       if (state->axis.info) {
                GSList *ptr, *children;
-               GogAxis *axis = state->axis.obj;
                GogAxisElemType et;
                XLSXAxisInfo *info = state->axis.info;
 
@@ -919,13 +932,27 @@ xlsx_axis_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
                        break;
                }
                g_slist_free (children);
+       }
+
+       xlsx_chart_pop_obj (state);
 
-               state->axis.obj  = NULL;
+       if (state->axis.info)
                state->axis.info = NULL;
+       else if (axis) {
+               if (gog_object_is_deletable (GOG_OBJECT (axis))) {
+#ifdef DEBUG_AXIS
+                       g_printerr ("Deleting axis %p\n", axis);
+#endif
+                       gog_object_clear_parent (GOG_OBJECT (axis));
+                       g_object_unref (axis);
+               } else {
+#ifdef DEBUG_AXIS
+                       g_printerr ("Axis %p is not deletable\n", axis);
+#endif
+               }
        }
 
-       xlsx_chart_pop_obj (state);
-       state->axis.info = NULL;
+       state->axis.obj  = NULL;
 }
 
 static void xlsx_chart_area (GsfXMLIn *xin, G_GNUC_UNUSED xmlChar const **attrs) { xlsx_chart_add_plot (xin, 
"GogAreaPlot"); }


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