From faa42f57f170ab45b0fd2920104d5b5036860c2b Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Fri, 8 Nov 2013 08:45:41 +0100 Subject: [PATCH] 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 5d157a0cc..834c0ba7a 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 cd9528b1c..10ee6c3fc 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); }