Patch: better implementation for "dispose" in TnyCamelAccount and TnyCamelStoreAccount



	Hi,

	Two patches.

**First patch: tinymail-tny-camel-account-dispose.patch**

It makes TnyCamelAccount disconnect on dispose. This is required for
allowing shutdown of connections without needing to have all references
freed. The idea is doing a dispose just before the intended final
shutdown of all accounts in execution.

Changelog is:

* libtinymail-camel/tny-camel-account.c: implement dispose handler,
  forcing disconnection of account.

**Second patch: tinymail-tny-camel-store-account-dispose-fixes.patch**

Second patch just fixes TnyCamelStoreAccount implementation, as it
doesn't set to NULL the freed variables. So subsequent calls to it may
crash. It also calls parent dispose method.

Changelog is:

* libtinymail-camel/tny-camel-store-account.c: set to NULL variables
  freed in dispose, so that next calls to dispose or finalize don't
  crash. Also call to parent class dispose.

-- 
José Dapena Paz <jdapena igalia com>
Igalia
diff --git a/ChangeLog b/ChangeLog
index e1f2fa9..656b420 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-07-21  Jose Dapena Paz  <jdapena igalia com>
+
+	* libtinymail-camel/tny-camel-account.c: implement dispose handler,
+	forcing disconnection of account.
+
 2009-07-20  Jose Dapena Paz  <jdapena igalia com>
 
 	* libtinymailui-gtk/tny-gtk-folder-list-store.c (get_parent_full_name):
diff --git a/libtinymail-camel/tny-camel-account.c b/libtinymail-camel/tny-camel-account.c
index d4ad188..f6ea644 100644
--- a/libtinymail-camel/tny-camel-account.c
+++ b/libtinymail-camel/tny-camel-account.c
@@ -2120,6 +2120,35 @@ tny_camel_account_get_supported_secure_authentication (TnyCamelAccount *self, Tn
 
 
 static void
+tny_camel_account_dispose (GObject *object)
+{
+	TnyCamelAccount *self = (TnyCamelAccount *)object;
+	TnyCamelAccountPriv *priv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self);
+	CamelException ex = CAMEL_EXCEPTION_INITIALISER;
+
+	if (priv->service && CAMEL_IS_SERVICE (priv->service))
+	{
+		priv->service->connecting = NULL;
+		priv->service->disconnecting = NULL;
+		priv->service->reconnecter = NULL;
+		priv->service->reconnection = NULL;
+		camel_service_disconnect (CAMEL_SERVICE (priv->service), FALSE, &ex);
+	}
+
+	if (priv->session) {
+		_tny_session_camel_unregister_account (priv->session, (TnyCamelAccount*) object);    
+		camel_object_unref (priv->session);
+		priv->session = NULL;
+	}
+	_tny_camel_account_start_camel_operation (self, NULL, NULL, NULL);
+	_tny_camel_account_stop_camel_operation (self);
+
+	(*parent_class->dispose) (object);
+
+	return;
+}
+
+static void
 tny_camel_account_finalize (GObject *object)
 {
 	TnyCamelAccount *self = (TnyCamelAccount *)object;
@@ -2334,6 +2363,7 @@ tny_camel_account_class_init (TnyCamelAccountClass *class)
 	class->set_online= tny_camel_account_set_online_default;
 
 	object_class->finalize = tny_camel_account_finalize;
+	object_class->dispose = tny_camel_account_dispose;
 
 	g_type_class_add_private (object_class, sizeof (TnyCamelAccountPriv));
 
diff --git a/ChangeLog b/ChangeLog
index 656b420..7c4c541 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2009-07-21  Jose Dapena Paz  <jdapena igalia com>
 
+	* libtinymail-camel/tny-camel-store-account.c: set to NULL variables
+	freed in dispose, so that next calls to dispose or finalize don't
+	crash. Also call to parent class dispose.
+
 	* libtinymail-camel/tny-camel-account.c: implement dispose handler,
 	forcing disconnection of account.
 
diff --git a/libtinymail-camel/tny-camel-store-account.c b/libtinymail-camel/tny-camel-store-account.c
index 5ec73e1..31e485d 100644
--- a/libtinymail-camel/tny-camel-store-account.c
+++ b/libtinymail-camel/tny-camel-store-account.c
@@ -915,9 +915,14 @@ tny_camel_store_account_dispose (GObject *object)
 	{
 		camel_store_free_folder_info (priv->iter_store, priv->iter);
 		camel_object_unref (CAMEL_OBJECT (priv->iter_store));
+		priv->iter_store = NULL;
+		priv->iter = NULL;
 	}
 
 	g_object_unref (priv->msg_queue);
+	priv->msg_queue = NULL;
+
+	(*parent_class->dispose) (object);
 
 	return;
 }


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