[glib/wip/gcleanup: 42/78] gobject: Don't leak pspecs for ininstantiated interfaces



commit 64110d422557dae04fc110c46bc9655274cfee0b
Author: Stef Walter <stefw gnome org>
Date:   Fri Nov 8 08:45:41 2013 +0100

    gobject: Don't leak pspecs for ininstantiated interfaces
    
    Remove the awkward ownerhsip of pspec by the object. pspecs are
    now only owned by the pool, which makes things more predictable.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711778

 gobject/gobject.c |    4 ++--
 gobject/gparam.c  |    9 ++++-----
 2 files changed, 6 insertions(+), 7 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index 4cdd80e..d638366 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -436,9 +436,8 @@ _g_object_type_free_pspecs (GType type)
     {
       GParamSpec *pspec = node->data;
       
-      g_param_spec_pool_remove (pspec_pool, pspec);
       PARAM_SPEC_SET_PARAM_ID (pspec, 0);
-      g_param_spec_unref (pspec);
+      g_param_spec_pool_remove (pspec_pool, pspec);
     }
   g_list_free (list);
 }
@@ -533,6 +532,7 @@ install_property_internal (GType       g_type,
   g_param_spec_ref_sink (pspec);
   PARAM_SPEC_SET_PARAM_ID (pspec, property_id);
   g_param_spec_pool_insert (pspec_pool, pspec, g_type);
+  g_param_spec_unref (pspec);
 }
 
 /**
diff --git a/gobject/gparam.c b/gobject/gparam.c
index 686e91b..3ee716c 100644
--- a/gobject/gparam.c
+++ b/gobject/gparam.c
@@ -917,7 +917,8 @@ g_param_spec_pool_new (gboolean type_prefixing)
 
   memcpy (&pool->mutex, &init_mutex, sizeof (init_mutex));
   pool->type_prefixing = type_prefixing != FALSE;
-  pool->hash_table = g_hash_table_new (param_spec_pool_hash, param_spec_pool_equals);
+  pool->hash_table = g_hash_table_new_full (param_spec_pool_hash, param_spec_pool_equals,
+                                            NULL, (GDestroyNotify)g_param_spec_unref);
 
   return pool;
 }
@@ -957,7 +958,7 @@ g_param_spec_pool_insert (GParamSpecPool *pool,
       g_mutex_lock (&pool->mutex);
       pspec->owner_type = owner_type;
       g_param_spec_ref (pspec);
-      g_hash_table_insert (pool->hash_table, pspec, pspec);
+      g_hash_table_add (pool->hash_table, pspec);
       g_mutex_unlock (&pool->mutex);
     }
   else
@@ -983,9 +984,7 @@ g_param_spec_pool_remove (GParamSpecPool *pool,
   if (pool && pspec)
     {
       g_mutex_lock (&pool->mutex);
-      if (g_hash_table_remove (pool->hash_table, pspec))
-       g_param_spec_unref (pspec);
-      else
+      if (!g_hash_table_remove (pool->hash_table, pspec))
        g_warning (G_STRLOC ": attempt to remove unknown pspec '%s' from pool", pspec->name);
       g_mutex_unlock (&pool->mutex);
     }


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