From 9f073d6025a94379ba9e17f3a5eff44bed3b9925 Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Fri, 7 Nov 2008 17:50:00 +0000 Subject: [PATCH 1/1] * Fixes NB#91356, fixes a couple of memory leaks pmo-trunk-r6242 --- src/modest-protocol-registry.c | 17 ++++++++++++++--- src/modest-singletons.c | 6 ++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/modest-protocol-registry.c b/src/modest-protocol-registry.c index 3aae13b..be567d7 100644 --- a/src/modest-protocol-registry.c +++ b/src/modest-protocol-registry.c @@ -154,7 +154,8 @@ modest_protocol_registry_instance_init (ModestProtocolRegistry *obj) priv = MODEST_PROTOCOL_REGISTRY_GET_PRIVATE (obj); - priv->tags_table = g_hash_table_new (g_str_hash, g_str_equal); + priv->tags_table = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, (GDestroyNotify) g_hash_table_unref); priv->priorities = g_hash_table_new (g_direct_hash, g_direct_equal); modest_protocol_registry_create_tag (obj, TAG_ALL_PROTOCOLS); @@ -163,6 +164,15 @@ modest_protocol_registry_instance_init (ModestProtocolRegistry *obj) static void modest_protocol_registry_finalize (GObject *obj) { + ModestProtocolRegistryPrivate *priv; + + priv = MODEST_PROTOCOL_REGISTRY_GET_PRIVATE (obj); + + /* Free hash tables */ + if (priv->tags_table) + g_hash_table_unref (priv->tags_table); + if (priv->priorities) + g_hash_table_unref (priv->priorities); G_OBJECT_CLASS (parent_class)->finalize (obj); } @@ -205,7 +215,7 @@ modest_protocol_registry_add (ModestProtocolRegistry *self, ModestProtocol *prot tag_table = g_hash_table_lookup (priv->tags_table, node->data); if (tag_table == NULL) tag_table = modest_protocol_registry_create_tag (self, node->data); - g_hash_table_insert (tag_table, GINT_TO_POINTER (modest_protocol_get_type_id (protocol)), protocol); + g_hash_table_insert (tag_table, GINT_TO_POINTER (modest_protocol_get_type_id (protocol)), g_object_ref (protocol)); } g_slist_free (tags_list); } @@ -372,7 +382,8 @@ modest_protocol_registry_create_tag (ModestProtocolRegistry *self, const gchar * g_assert (tag != NULL); priv = MODEST_PROTOCOL_REGISTRY_GET_PRIVATE (self); - tag_table = g_hash_table_new (g_direct_hash, g_direct_equal); + tag_table = g_hash_table_new_full (g_direct_hash, g_direct_equal, + NULL, g_object_unref); g_hash_table_insert (priv->tags_table, g_strdup (tag), tag_table); return tag_table; diff --git a/src/modest-singletons.c b/src/modest-singletons.c index 8b9ed7d..76f6ec1 100644 --- a/src/modest-singletons.c +++ b/src/modest-singletons.c @@ -248,6 +248,12 @@ modest_singletons_finalize (GObject *obj) priv->plugin_factory = NULL; } + if (priv->protocol_registry) { + MODEST_DEBUG_VERIFY_OBJECT_LAST_REF(priv->protocol_registry,""); + g_object_unref (G_OBJECT(priv->protocol_registry)); + priv->protocol_registry = NULL; + } + /* It is important that the account manager is uninitialized after * the mail op queue is uninitialized because the mail op queue * cancells any mail operations which in turn access the account -- 1.7.9.5