[evolution-mapi] Bug #638821 - Abort in e-addressbook-factory due to freed backend



commit 84b51006eb2f95f979e8908f01df2730bc35549a
Author: Milan Crha <mcrha redhat com>
Date:   Fri Aug 5 19:07:55 2011 +0200

    Bug #638821 - Abort in e-addressbook-factory due to freed backend

 src/addressbook/e-book-backend-mapi.c |   41 +++++++++++++++++++++++++++++++-
 1 files changed, 39 insertions(+), 2 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-mapi.c b/src/addressbook/e-book-backend-mapi.c
index e5f623b..1be857a 100644
--- a/src/addressbook/e-book-backend-mapi.c
+++ b/src/addressbook/e-book-backend-mapi.c
@@ -291,6 +291,18 @@ ebbm_build_cache_update_restriction (EBookBackendMAPI *ebma, TALLOC_CTX *mem_ctx
 	return restriction;
 }
 
+static gboolean
+unref_backend_idle_cb (gpointer data)
+{
+	EBookBackendMAPI *ebma = data;
+
+	g_return_val_if_fail (ebma != NULL, FALSE);
+
+	g_object_unref (ebma);
+
+	return FALSE;
+}
+
 static gpointer
 ebbm_update_cache_cb (gpointer data)
 {
@@ -366,6 +378,9 @@ ebbm_update_cache_cb (gpointer data)
 	/* indicate the thread is not running */
 	g_cancellable_cancel (priv->update_cache);
 
+	/* May unref it out of the thread, in case it's the last reference to it */
+	g_idle_add (unref_backend_idle_cb, ebma);
+
 	return NULL;
 }
 
@@ -520,6 +535,11 @@ ebbm_authenticate_user (EBookBackendMAPI *ebma, GCancellable *cancellable, ECred
 
 		e_book_backend_mapi_lock_connection (ebma);
 
+		if (g_cancellable_set_error_if_cancelled (cancellable, error)) {
+			e_book_backend_mapi_unlock_connection (ebma);
+			return;
+		}
+
 		old_conn = priv->conn;
 		priv->conn = NULL;
 
@@ -553,8 +573,13 @@ ebbm_authenticate_user (EBookBackendMAPI *ebma, GCancellable *cancellable, ECred
 
 		ebbm_notify_connection_status (ebma, TRUE);
 
-		/* if (priv->marked_for_offline) */
+		if (!g_cancellable_is_cancelled (cancellable) /* && priv->marked_for_offline */) {
+			g_object_ref (ebma);
+
 			priv->update_cache_thread = g_thread_create (ebbm_update_cache_cb, ebma, TRUE, NULL);
+			if (!priv->update_cache_thread)
+				g_object_unref (ebma);
+		}
 	}
 }
 
@@ -706,7 +731,8 @@ ebbm_book_view_thread (gpointer data)
 		g_error_free (error);
 
 	g_object_unref (bvtd->book_view);
-	g_object_unref (bvtd->ebma);
+	/* May unref it out of the thread, in case it's the last reference to it */
+	g_idle_add (unref_backend_idle_cb, bvtd->ebma);
 	g_free (bvtd);
 
 	return NULL;
@@ -991,6 +1017,7 @@ ebbm_operation_cb (OperationBase *op, gboolean cancelled, EBookBackend *backend)
 		g_object_unref (op->cancellable);
 	if (op->book)
 		g_object_unref (op->book);
+	g_object_unref (ebma);
 	g_free (op);
 }
 
@@ -1008,6 +1035,7 @@ base_op_abstract (EBookBackend *backend, EDataBook *book, guint32 opid, GCancell
 	priv = ebbm->priv;
 	g_return_if_fail (priv != NULL);
 
+	g_object_ref (ebbm);
 	if (book)
 		g_object_ref (book);
 	if (cancellable)
@@ -1036,6 +1064,7 @@ str_op_abstract (EBookBackend *backend, EDataBook *book, guint32 opid, GCancella
 	priv = ebbm->priv;
 	g_return_if_fail (priv != NULL);
 
+	g_object_ref (ebbm);
 	if (book)
 		g_object_ref (book);
 	if (cancellable)
@@ -1086,6 +1115,7 @@ ebbm_op_open (EBookBackend *backend, EDataBook *book, guint32 opid, GCancellable
 	priv = ebbm->priv;
 	g_return_if_fail (priv != NULL);
 
+	g_object_ref (ebbm);
 	if (book)
 		g_object_ref (book);
 	if (cancellable)
@@ -1117,6 +1147,7 @@ ebbm_op_remove_contacts (EBookBackend *backend, EDataBook *book, guint32 opid, G
 	priv = ebbm->priv;
 	g_return_if_fail (priv != NULL);
 
+	g_object_ref (ebbm);
 	if (book)
 		g_object_ref (book);
 	if (cancellable)
@@ -1151,6 +1182,8 @@ ebbm_op_start_book_view (EBookBackend *backend, EDataBookView *book_view)
 	priv = ebbm->priv;
 	g_return_if_fail (priv != NULL);
 
+	g_object_ref (ebbm);
+
 	op = g_new0 (OperationBookView, 1);
 	op->base.ot = OP_START_BOOK_VIEW;
 	op->base.book = NULL;
@@ -1177,6 +1210,8 @@ ebbm_op_stop_book_view (EBookBackend *backend, EDataBookView *book_view)
 	priv = ebbm->priv;
 	g_return_if_fail (priv != NULL);
 
+	g_object_ref (ebbm);
+
 	op = g_new0 (OperationBookView, 1);
 	op->base.ot = OP_STOP_BOOK_VIEW;
 	op->base.book = NULL;
@@ -1205,6 +1240,8 @@ ebbm_op_authenticate_user (EBookBackend *backend, GCancellable *cancellable, ECr
 	if (cancellable)
 		g_object_ref (cancellable);
 
+	g_object_ref (ebbm);
+
 	op = g_new0 (OperationAuthenticateUser, 1);
 	op->base.ot = OP_AUTHENTICATE_USER;
 	op->base.book = NULL;



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