[tracker/clientapi-2: 2/4] Dealing with a memory leak for the TrackerMiner of the Evolution plugin



commit 74c51c3c47b0d4b628a9189bbb3bec5590ac974f
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Jan 14 12:46:16 2010 +0100

    Dealing with a memory leak for the TrackerMiner of the Evolution plugin

 src/plugins/evolution/tracker-evolution-plugin.c |   57 +++++++++++++++-------
 1 files changed, 39 insertions(+), 18 deletions(-)
---
diff --git a/src/plugins/evolution/tracker-evolution-plugin.c b/src/plugins/evolution/tracker-evolution-plugin.c
index 1f4373c..42699e9 100644
--- a/src/plugins/evolution/tracker-evolution-plugin.c
+++ b/src/plugins/evolution/tracker-evolution-plugin.c
@@ -199,7 +199,7 @@ typedef struct {
 
 static TrackerEvolutionPlugin *manager = NULL;
 static GStaticRecMutex glock = G_STATIC_REC_MUTEX_INIT;
-static guint register_count = 0;
+static guint register_count = 0, walk_count = 0;
 static ThreadPool *sparql_pool = NULL, *folder_pool = NULL;
 
 /* Prototype declarations */
@@ -1832,6 +1832,8 @@ on_got_folderinfo_register (CamelStore *store,
 	g_free (reg_info->uri);
 	g_free (reg_info);
 
+	walk_count--;
+
 	return TRUE;
 }
 
@@ -1868,6 +1870,8 @@ register_account (TrackerEvolutionPlugin *self,
 	reg_info->uri = g_strdup (uri);
 	reg_info->account = g_object_ref (account);
 
+	walk_count++;
+
 	/* Get the account's folder-info and register it asynchronously */
 	mail_get_folderinfo (store, NULL, on_got_folderinfo_register, reg_info);
 
@@ -2061,12 +2065,30 @@ name_owner_changed_cb (DBusGProxy *proxy,
 }
 
 static void
-enable_plugin (void)
+enable_plugin_real (void)
 {
-	if (manager) {
-		g_object_unref (manager);
+	manager = g_object_new (TRACKER_TYPE_EVOLUTION_PLUGIN,
+		                        "name", "Emails", NULL);
+
+	g_signal_emit_by_name (manager, "started");
+}
+
+static gboolean 
+enable_plugin_try (gpointer user_data)
+{
+	if (walk_count == 0) {
+		enable_plugin_real ();
+		return FALSE;
 	}
 
+	return TRUE;
+}
+
+static void
+enable_plugin (void)
+{
+	/* Deal with https://bugzilla.gnome.org/show_bug.cgi?id=606940 */
+
 	if (sparql_pool) {
 		thread_pool_destroy (sparql_pool);
 		sparql_pool = NULL;
@@ -2077,10 +2099,16 @@ enable_plugin (void)
 		folder_pool = NULL;
 	}
 
-	manager = g_object_new (TRACKER_TYPE_EVOLUTION_PLUGIN,
-	                        "name", "Emails", NULL);
+	if (manager) {
+		g_object_unref (manager);
+	}
 
-	g_signal_emit_by_name (manager, "started");
+	if (walk_count > 0) {
+		g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, 1,
+		                            enable_plugin_try, NULL, NULL);
+	} else {
+		enable_plugin_real ();
+	}
 }
 
 
@@ -2220,21 +2248,14 @@ tracker_evolution_plugin_init (TrackerEvolutionPlugin *plugin)
 }
 
 static void
-dbus_connect_closure (gpointer data, GClosure *closure)
-{
-	g_object_unref (data);
-}
-
-
-static void
 listnames_fini (gpointer data)
 {
 	TrackerEvolutionPluginPrivate *priv = TRACKER_EVOLUTION_PLUGIN_GET_PRIVATE (data);
 
 	dbus_g_proxy_connect_signal (priv->dbus_proxy, "NameOwnerChanged",
 	                             G_CALLBACK (name_owner_changed_cb),
-	                             g_object_ref (data),
-	                             dbus_connect_closure);
+	                             data,
+	                             NULL);
 
 	g_object_unref (data);
 }
@@ -2323,8 +2344,8 @@ resuming_fini (gpointer data)
 
 	dbus_g_proxy_connect_signal (priv->dbus_proxy, "NameOwnerChanged",
 	                             G_CALLBACK (name_owner_changed_cb),
-	                             g_object_ref (data),
-	                             dbus_connect_closure);
+	                             data,
+	                             NULL);
 
 	g_object_unref (data);
 }



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