[PATCH 01/18] Do unrefs in dispose, not finalise for tny-camel-folder and tny-camel-store-account.



Do unrefs in dispose, not finalise for tny-camel-folder and tny-camel-store-account.

---
 ChangeLog                                   |    8 +++-
libtinymail-camel/tny-camel-folder.c | 59 ++++++++++++++++++++-------
 libtinymail-camel/tny-camel-store-account.c |   18 ++++++--
 3 files changed, 64 insertions(+), 21 deletions(-)

--
Rob Taylor, Codethink Ltd. - http://codethink.co.uk
diff --git a/ChangeLog b/ChangeLog
index 4a3a20f..ab84b1d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -189,8 +189,6 @@
         * Don't get folders again when we change status to disconnected.
 
 2008-06-20  Jose Dapena Paz  <jdapena igalia com>
-
-	* libtinymail-camel/tny-camel-folder.c:
         Fix camel operation references
 
 	* libtinymail-camel/tny-camel-bs-mime-part.c:
@@ -237,6 +235,12 @@
 	* libtinymail/Makefile.am:
         Added stream cache implementation files.
 
+2008-06-12  Rob Taylor  <rob taylor codethink co uk>
+
+	* libtinymail-camel/tny-camel-folder.c:
+	* libtinymail-camel/tny-camel-store-account.c:
+	do unrefs in dispose, not finalise for tny-camel-folder and tny-camel-store-account.
+
 2008-06-10  Sergio Villar Senin  <svillar igalia com>
 
 	* libtinymail-maemo/tny-maemo-conic-device.c:
diff --git a/libtinymail-camel/tny-camel-folder.c b/libtinymail-camel/tny-camel-folder.c
index 1993ff8..d085121 100644
--- a/libtinymail-camel/tny-camel-folder.c
+++ b/libtinymail-camel/tny-camel-folder.c
@@ -6045,21 +6045,11 @@ _tny_camel_folder_freeup_observers (TnyCamelFolder *self, TnyCamelFolderPriv *pr
 }
 
 static void
-tny_camel_folder_finalize (GObject *object)
+tny_camel_folder_dispose (GObject *object)
 {
 	TnyCamelFolder *self = (TnyCamelFolder*) object;
 	TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (self);
 
-
-#ifdef DEBUG
-	g_print ("Finalizing TnyCamelFolder: %s\n", 
-		priv->folder_name?priv->folder_name:"(cleared)");
-
-	if (priv->reason_to_live != 0)
-		g_print ("Finalizing TnyCamelFolder, yet TnyHeader instances "
-		"are still alive: %d\n", priv->reason_to_live);
-#endif
-
 	if (priv->store)
 		camel_object_unref (priv->store);
 
@@ -6099,10 +6089,6 @@ tny_camel_folder_finalize (GObject *object)
 		priv->folder = NULL;
 	}
 
-	if (G_LIKELY (priv->cached_name))
-		g_free (priv->cached_name);
-	priv->cached_name = NULL;
-
 	if (G_LIKELY (priv->remove_strat))
 		g_object_unref (G_OBJECT (priv->remove_strat));
 	priv->remove_strat = NULL;
@@ -6115,6 +6101,48 @@ tny_camel_folder_finalize (GObject *object)
 
 	g_static_rec_mutex_unlock (priv->folder_lock);
 
+	return;
+}
+
+
+static void
+tny_camel_folder_finalize (GObject *object)
+{
+	TnyCamelFolder *self = (TnyCamelFolder*) object;
+	TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (self);
+
+
+#ifdef DEBUG
+	g_print ("Finalizing TnyCamelFolder: %s\n", 
+		priv->folder_name?priv->folder_name:"(cleared)");
+
+	if (priv->reason_to_live != 0)
+		g_print ("Finalizing TnyCamelFolder, yet TnyHeader instances "
+		"are still alive: %d\n", priv->reason_to_live);
+#endif
+
+	g_static_rec_mutex_lock (priv->folder_lock);
+	priv->dont_fkill = FALSE;
+
+	if (priv->account && TNY_IS_CAMEL_STORE_ACCOUNT (priv->account)) {
+		TnyCamelStoreAccountPriv *apriv = TNY_CAMEL_STORE_ACCOUNT_GET_PRIVATE (priv->account);
+		g_static_rec_mutex_lock (apriv->factory_lock);
+		apriv->managed_folders = g_list_remove (apriv->managed_folders, self);
+		g_static_rec_mutex_unlock (apriv->factory_lock);
+	}
+
+	if (G_LIKELY (priv->folder))
+	{
+		camel_object_unref (priv->folder);
+		priv->folder = NULL;
+	}
+
+	if (G_LIKELY (priv->cached_name))
+		g_free (priv->cached_name);
+	priv->cached_name = NULL;
+
+	g_static_rec_mutex_unlock (priv->folder_lock);
+
 	/* g_static_rec_mutex_free (priv->folder_lock); */
 	g_free (priv->folder_lock);
 	priv->folder_lock = NULL;
@@ -6205,6 +6233,7 @@ tny_camel_folder_class_init (TnyCamelFolderClass *class)
 
 	parent_class = g_type_class_peek_parent (class);
 	object_class = (GObjectClass*) class;
+	object_class->dispose = tny_camel_folder_dispose;
 	object_class->finalize = tny_camel_folder_finalize;
 
 	class->add_msg_async= tny_camel_folder_add_msg_async_default;
diff --git a/libtinymail-camel/tny-camel-store-account.c b/libtinymail-camel/tny-camel-store-account.c
index 27a561e..6b6c7a8 100644
--- a/libtinymail-camel/tny-camel-store-account.c
+++ b/libtinymail-camel/tny-camel-store-account.c
@@ -798,9 +798,8 @@ notify_store_observer_del (gpointer user_data, GObject *observer)
 	g_static_rec_mutex_unlock (priv->obs_lock);
 }
 
-
 static void
-tny_camel_store_account_finalize (GObject *object)
+tny_camel_store_account_dispose (GObject *object)
 {
 	TnyCamelStoreAccount *self = (TnyCamelStoreAccount *)object;
 	TnyCamelStoreAccountPriv *priv = TNY_CAMEL_STORE_ACCOUNT_GET_PRIVATE (self);
@@ -825,6 +824,18 @@ tny_camel_store_account_finalize (GObject *object)
 		camel_object_unref (CAMEL_OBJECT (priv->iter_store));
 	}
 
+	g_object_unref (priv->msg_queue);
+
+	return;
+}
+
+
+static void
+tny_camel_store_account_finalize (GObject *object)
+{
+	TnyCamelStoreAccount *self = (TnyCamelStoreAccount *)object;
+	TnyCamelStoreAccountPriv *priv = TNY_CAMEL_STORE_ACCOUNT_GET_PRIVATE (self);
+
 	/* g_static_rec_mutex_free (priv->factory_lock); */
 	g_free (priv->factory_lock);
 	priv->factory_lock = NULL;
@@ -833,8 +844,6 @@ tny_camel_store_account_finalize (GObject *object)
 	g_free (priv->obs_lock);
 	priv->obs_lock = NULL;
 
-	g_object_unref (priv->msg_queue);
-
 	(*parent_class->finalize) (object);
 
 	return;
@@ -2089,6 +2098,7 @@ tny_camel_store_account_class_init (TnyCamelStoreAccountClass *class)
 	parent_class = g_type_class_peek_parent (class);
 	object_class = (GObjectClass*) class;
 
+	object_class->dispose = tny_camel_store_account_dispose;
 	object_class->finalize = tny_camel_store_account_finalize;
 
 	TNY_CAMEL_ACCOUNT_CLASS (class)->try_connect= tny_camel_store_account_try_connect;



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