[gegl] gegl: fix memory management of gegl_chant_path()



commit 6561032d5c3dacf299827c8abd114ba50afdffe1
Author: Michael Natterer <mitch gimp org>
Date:   Wed May 22 09:16:43 2013 +0200

    gegl: fix memory management of gegl_chant_path()
    
    get_property(): don't allocate a new path if none exists, instead
    return NULL as expected from unset object properties. I'm sorry if
    this crashes some code, it was just wrong.
    
    set_property(): don't leak the previous path when a new one is set.
    
    Also, signal handler IDs are gulong not guint.

 gegl/gegl-chant.h |   27 ++++++++++++++-------------
 1 files changed, 14 insertions(+), 13 deletions(-)
---
diff --git a/gegl/gegl-chant.h b/gegl/gegl-chant.h
index 7b1c786..b2bafa0 100644
--- a/gegl/gegl-chant.h
+++ b/gegl/gegl-chant.h
@@ -433,7 +433,7 @@ struct _GeglChantO
 #define gegl_chant_curve(name, nick, blurb)                                     GeglCurve         *name;
 #define gegl_chant_seed(name, nick, blurb)                                      gint               name;
 #define gegl_chant_path(name, nick, blurb)                                      GeglPath          *name;\
-                                                                                guint path_changed_handler;
+                                                                                gulong path_changed_handler;
 
 #include GEGL_CHANT_C_FILE
 
@@ -565,9 +565,8 @@ get_property (GObject      *gobject,
       break;
 #define gegl_chant_path(name, nick, blurb)                    \
     case PROP_##name:                                         \
-      if (!properties->name)properties->name = gegl_path_new (); /* this feels ugly */\
       g_value_set_object (value, properties->name);           \
-      break;/*XXX*/
+      break;
 
 #include GEGL_CHANT_C_FILE
 
@@ -676,18 +675,20 @@ set_property (GObject      *gobject,
 #define gegl_chant_path(name, nick, blurb)                            \
     case PROP_##name:                                                 \
       if (properties->name != NULL)                                   \
-        {\
-          if (properties->path_changed_handler) \
-            g_signal_handler_disconnect (G_OBJECT (properties->name), properties->path_changed_handler);\
-         properties->path_changed_handler = 0;\
+        {                                                             \
+          if (properties->path_changed_handler)                       \
+            g_signal_handler_disconnect (G_OBJECT (properties->name), \
+                                         properties->path_changed_handler); \
+          properties->path_changed_handler = 0;                       \
+          g_object_unref (properties->name);                          \
         }                                                             \
-      properties->name = NULL;                                        \
-      if (g_value_peek_pointer (value))                               \
+      properties->name = g_value_dup_object (value);                  \
+      if (properties->name != NULL)                                   \
         {                                                             \
-          properties->name = g_value_dup_object (value);              \
-          properties->path_changed_handler = g_signal_connect (G_OBJECT (properties->name), "changed",   \
-          G_CALLBACK(path_changed), gobject);     \
-         }\
+          properties->path_changed_handler =                          \
+            g_signal_connect (G_OBJECT (properties->name), "changed", \
+                              G_CALLBACK(path_changed), gobject);     \
+         }                                                            \
       break; /*XXX*/
 
 #include GEGL_CHANT_C_FILE


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