Patch: some referencing problems fixes



	Hi,

	This patch fixes some reference problems (leaks and cycles) detected in
modest. We wanted to make as sure as we could that no pending threads
were running when camel shutdown happened (to reduce risk of getting the
infamous __nptl_deallocate_tsd crash).

	The main problem is that we weren't able to warrant that the imap idle
thread would die before camel shutdown happens. I changed a bit the code
to force waiting for idle thread finishing (and freeing the camel imap
store and folder then).

	About TnyDevice  reference in TnySessionCamel we make it explicit. We
include other leak fixes.

	And finally, I added code to avoid getting folders again when we get a
notification of disconnection of the store in folder view.

Changelog would be:
* libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c:
        * Don't set in_idle to false so that join works properly.
        * On disconnecting we forze a stop_idle so we warrant idle
          thread has died when we disconnect.
        * Send let idle die commands on disconnecting.
        * It's very important to make the idle thread die on time as it
          keeps a reference to the folder. Folder keeps a reference to
          this store, and then store should finish idle soon to be able
          to finalize (cycle reference).
* libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c:
        * On finishing the idle thread we state we're out of it.    
* libtinymail-camel/camel-lite/camel.c:
        * Avoid running internal methods of camel_shutdown two times if
          we can call shutdown two times.               
* libtinymail-camel/tny-session-camel.c:
        * Keep a proper reference to TnyDevice.
* libtinymail-camel/tny-camel-store-account.c:
        * Free the iter store reference on finalising.
* libtinymail-camel/tny-camel-account.c:
        * Set service to null after unreffing it.
* libtinymailui-gtk/tny-gtk-folder-store-tree-model.c:
        * Don't get folders again when we change status to disconnected.


-- 
José Dapena Paz <jdapena igalia com>
Igalia

Index: libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c	(revision 3704)
+++ libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-store.c	(working copy)
@@ -234,7 +234,6 @@
 		idle_debug ("Sending DONE in let_idle_die\n");
 		CAMEL_SERVICE_REC_LOCK (store, connect_lock);
 		nwritten = camel_stream_printf (store->ostream, "DONE\r\n");
-		store->in_idle = FALSE;
 		if (nwritten != -1) {
 			resp = NULL;
 			while ((camel_imap_command_response_idle (store, &resp, &ex)) == CAMEL_IMAP_RESPONSE_UNTAGGED) {
@@ -397,6 +396,8 @@
 
 	let_idle_die (imap_store, TRUE);
 
+	camel_imap_store_stop_idle (imap_store);
+
 	if (imap_store->current_folder) {
 		camel_object_unhook_event (imap_store->current_folder, "finalize",
 					   _camel_imap_store_current_folder_finalize, imap_store);
@@ -2100,7 +2101,8 @@
 
 	imap_debug ("imap_connect_offline\n");
 
-	/* let_idle_die (store, TRUE); */
+	let_idle_die (store, TRUE);
+	camel_imap_store_stop_idle (store);
 
 	if (!disco_store->diary)
 		return FALSE;
@@ -2117,7 +2119,8 @@
 
 	imap_debug ("imap_disconnect_offline\n");
 
-	/*let_idle_die (store, TRUE);*/
+	let_idle_die (store, TRUE);
+	camel_imap_store_stop_idle (store);
 
 	if (store->istream) {
 		camel_stream_close(store->istream);
Index: libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c
===================================================================
--- libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c	(revision 3704)
+++ libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c	(working copy)
@@ -4220,6 +4220,7 @@
 		g_mutex_unlock (info->mutex);
 	}
 
+	store->in_idle = FALSE;
 	camel_object_unref (folder);
 
 	g_thread_exit (retval);
Index: libtinymail-camel/camel-lite/camel/camel.c
===================================================================
--- libtinymail-camel/camel-lite/camel/camel.c	(revision 3704)
+++ libtinymail-camel/camel-lite/camel/camel.c	(working copy)
@@ -54,6 +54,7 @@
 	if (!initialised)
 		return;
 
+	initialised = FALSE;
 	certdb = camel_certdb_get_default ();
 	if (certdb) {
 		camel_certdb_save (certdb);
@@ -65,7 +66,6 @@
 	PR_Cleanup ();
 #endif /* HAVE_NSS */
 
-	initialised = FALSE;
 }
 
 int
Index: libtinymail-camel/tny-session-camel.c
===================================================================
--- libtinymail-camel/tny-session-camel.c	(revision 3704)
+++ libtinymail-camel/tny-session-camel.c	(working copy)
@@ -982,7 +982,7 @@
 	/* TNY TODO: proper reference counting here please! Note that we can't
 	 * have embraced references either. So be careful! */
 
-	priv->device = device;
+	priv->device = g_object_ref (device);
 
 	return;
 }
@@ -1091,6 +1091,10 @@
 			priv->connchanged_signal);
 	}
 
+	if (priv->device) {
+		g_object_unref (priv->device);
+	}
+
 	if (priv->ui_lock)
 		g_object_unref (G_OBJECT (priv->ui_lock));
 
Index: libtinymail-camel/tny-camel-store-account.c
===================================================================
--- libtinymail-camel/tny-camel-store-account.c	(revision 3704)
+++ libtinymail-camel/tny-camel-store-account.c	(working copy)
@@ -1412,6 +1412,10 @@
 	priv->iter = iter;
 	priv->cant_reuse_iter = FALSE;
 
+	if (priv->iter_store) {
+		camel_object_unref (CAMEL_OBJECT (store));
+	}
+
 	camel_object_ref (CAMEL_OBJECT (store));
 	priv->iter_store = store;
 
Index: libtinymail-camel/tny-camel-account.c
===================================================================
--- libtinymail-camel/tny-camel-account.c	(revision 3704)
+++ libtinymail-camel/tny-camel-account.c	(working copy)
@@ -2162,6 +2162,7 @@
 			priv->service->url->user = g_strdup ("non existing dummy user");
 		}
 		camel_object_unref (CAMEL_OBJECT (priv->service));
+		priv->service = NULL;
 	}
 
 	if (G_LIKELY (priv->cache_location))
Index: libtinymailui-gtk/tny-gtk-folder-store-tree-model.c
===================================================================
--- libtinymailui-gtk/tny-gtk-folder-store-tree-model.c	(revision 3704)
+++ libtinymailui-gtk/tny-gtk-folder-store-tree-model.c	(working copy)
@@ -338,7 +338,7 @@
 	 * might have arrived. We'll need to scan for those, so we'll recursively
 	 * start asking the account about its folders. */
 
-	if (status == TNY_CONNECTION_STATUS_RECONNECTING)
+	if (status == TNY_CONNECTION_STATUS_RECONNECTING || status == TNY_CONNECTION_STATUS_DISCONNECTED)
 		return;
 
 	list = tny_simple_list_new ();


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