From 3491c6625c93bf98f587be1f7889b17ce8ecc35c Mon Sep 17 00:00:00 2001 From: Kalev Lember Date: Fri, 4 Oct 2013 21:28:45 +0200 Subject: [PATCH] background: Fix reference counting in background XML loader Commit b9e3603ba4d6b494c0659cbc0196ef9f81fa6a60 added an unref to fix a memory leak, but it went to a wrong place -- in XML loader, all items are stored in a hash table that takes ownership of them, and destroyed when the hash table goes away. This commit fixes the reference counting in the XML loader and adds explicit g_object_ref / g_strdup when inserting values to the hash table to make the memory management more obvious. The following commit fixes the real leak. https://bugzilla.gnome.org/show_bug.cgi?id=709453 --- panels/background/cc-background-xml.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/panels/background/cc-background-xml.c b/panels/background/cc-background-xml.c index 67a7beb40..9264c88de 100644 --- a/panels/background/cc-background-xml.c +++ b/panels/background/cc-background-xml.c @@ -311,13 +311,16 @@ cc_background_xml_load_xml_internal (CcBackgroundXml *xml, } g_object_set (G_OBJECT (item), "flags", flags, NULL); - g_hash_table_insert (xml->priv->wp_hash, id, item); - /* Don't free ID, we added it to the hash table */ + g_hash_table_insert (xml->priv->wp_hash, + g_strdup (id), + g_object_ref (item)); if (in_thread) emit_added_in_idle (xml, g_object_ref (item)); else g_signal_emit (G_OBJECT (xml), signals[ADDED], 0, item); + g_object_unref (item); + g_free (id); retval = TRUE; } }