[dia] svg: plug memory leaks triggered by gradient-variations.svg



commit 80a86bb3e53e8a7882a172ec412e9aac986a9b28
Author: Hans Breuer <hans breuer org>
Date:   Wed Jan 1 17:30:05 2014 +0100

    svg: plug memory leaks triggered by gradient-variations.svg
    
    Ooops, every pattern was leaked;)

 objects/standard/beziergon.c |    2 ++
 objects/standard/box.c       |    2 ++
 objects/standard/ellipse.c   |    2 ++
 objects/standard/polygon.c   |    2 ++
 plug-ins/svg/svg-import.c    |   36 +++++++++++++++++++++++-------------
 5 files changed, 31 insertions(+), 13 deletions(-)
---
diff --git a/objects/standard/beziergon.c b/objects/standard/beziergon.c
index ec8bbc9..4d3ae01 100644
--- a/objects/standard/beziergon.c
+++ b/objects/standard/beziergon.c
@@ -314,6 +314,8 @@ beziergon_create(Point *startpoint,
 static void
 beziergon_destroy(Beziergon *beziergon)
 {
+  if (beziergon->pattern)
+    g_object_unref (beziergon->pattern);
   beziershape_destroy(&beziergon->bezier);
 }
 
diff --git a/objects/standard/box.c b/objects/standard/box.c
index cb301a7..f950a04 100644
--- a/objects/standard/box.c
+++ b/objects/standard/box.c
@@ -478,6 +478,8 @@ box_create(Point *startpoint,
 static void
 box_destroy(Box *box)
 {
+  if (box->pattern)
+    g_object_unref (box->pattern);
   element_destroy(&box->element);
 }
 
diff --git a/objects/standard/ellipse.c b/objects/standard/ellipse.c
index d578931..d2d793b 100644
--- a/objects/standard/ellipse.c
+++ b/objects/standard/ellipse.c
@@ -452,6 +452,8 @@ ellipse_create(Point *startpoint,
 static void
 ellipse_destroy(Ellipse *ellipse)
 {
+  if (ellipse->pattern)
+    g_object_unref (ellipse->pattern);
   element_destroy(&ellipse->element);
 }
 
diff --git a/objects/standard/polygon.c b/objects/standard/polygon.c
index d53d423..72c9bb3 100644
--- a/objects/standard/polygon.c
+++ b/objects/standard/polygon.c
@@ -295,6 +295,8 @@ polygon_create(Point *startpoint,
 static void
 polygon_destroy(Polygon *polygon)
 {
+  if (polygon->pattern)
+    g_object_unref (polygon->pattern);
   polyshape_destroy(&polygon->poly);
 }
 
diff --git a/plug-ins/svg/svg-import.c b/plug-ins/svg/svg-import.c
index cb97aa1..1b1e684 100644
--- a/plug-ins/svg/svg-import.c
+++ b/plug-ins/svg/svg-import.c
@@ -397,6 +397,23 @@ _node_css_parse_style (xmlNodePtr node,
   }
 }
 
+static void
+_set_pattern_from_key (DiaObject *obj, BoolProperty *bprop,
+                      GHashTable *pattern_ht, const gchar *key)
+{
+  ObjectChange *change = NULL;
+  DiaPattern *pattern = g_hash_table_lookup (pattern_ht, key);
+  if (pattern) {
+    change = dia_object_set_pattern (obj, pattern);
+    /* activate "show_background" */
+    bprop->bool_data = TRUE;
+  }
+  if (change) { /* throw it away, no one needs it here  */
+    change->free (change);
+    g_free (change);
+  }
+}
+
 /* apply SVG style to object */
 static void
 apply_style(DiaObject *obj, xmlNodePtr node, DiaSvgStyle *parent_style,
@@ -411,6 +428,7 @@ apply_style(DiaObject *obj, xmlNodePtr node, DiaSvgStyle *parent_style,
       EnumProperty *eprop;
       real scale = 1.0;
 
+
       xmlChar *str = xmlGetProp(node, (const xmlChar *)"transform");
       if (str) {
          DiaMatrix *m = dia_svg_parse_transform ((char *)str, user_scale);
@@ -484,12 +502,7 @@ apply_style(DiaObject *obj, xmlNodePtr node, DiaSvgStyle *parent_style,
        const char *right = strrchr ((const char*)str, ')');
        if (left && right) {
          gchar *key = g_strndup (left + 5, right - left - 5);
-         DiaPattern *pattern = g_hash_table_lookup (pattern_ht, key);
-         if (pattern) {
-           dia_object_set_pattern (obj, pattern);
-           /* activate "show_background" */
-           bprop->bool_data = TRUE;
-         }
+         _set_pattern_from_key (obj, bprop, pattern_ht, key);
          g_free (key);
        }
        xmlFree(str);        
@@ -501,12 +514,7 @@ apply_style(DiaObject *obj, xmlNodePtr node, DiaSvgStyle *parent_style,
          const char *right = left ? strrchr (left, ')') : NULL;
          if (left && right) {
            gchar *key = g_strndup (left + 10, right - left - 10);
-           DiaPattern *pattern = g_hash_table_lookup (pattern_ht, key);
-           if (pattern) {
-             dia_object_set_pattern (obj, pattern);
-             /* activate "show_background" */
-             bprop->bool_data = TRUE;
-           }
+           _set_pattern_from_key (obj, bprop, pattern_ht, key);
            g_free (key);
          }
          xmlFree (str);
@@ -1147,8 +1155,10 @@ read_image_svg(xmlNodePtr node, DiaSvgStyle *parent_style,
 
          new_obj = create_standard_image(x, y, width, height, NULL);
          change = dia_object_set_pixbuf (new_obj, pixbuf);
-         if (change) /* throw it away, noone needs it here  */
+         if (change) { /* throw it away, noone needs it here  */
            change->free (change);
+            g_free (change);
+          }
          g_object_unref (pixbuf);
        }
       }


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