[evolution-exchange] Bug #634971 - Crash in update_cache() due to freed backend



commit 797dec817303a5e4d6eeb731661dc190f3d65881
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jun 23 13:14:16 2011 +0200

    Bug #634971 - Crash in update_cache() due to freed backend

 addressbook/e-book-backend-exchange.c      |   17 ++++++++++++-----
 calendar/e-cal-backend-exchange-calendar.c |   14 +++++++++++---
 calendar/e-cal-backend-exchange-tasks.c    |   14 +++++++++++---
 3 files changed, 34 insertions(+), 11 deletions(-)
---
diff --git a/addressbook/e-book-backend-exchange.c b/addressbook/e-book-backend-exchange.c
index 402ee63..13587f0 100644
--- a/addressbook/e-book-backend-exchange.c
+++ b/addressbook/e-book-backend-exchange.c
@@ -643,10 +643,13 @@ build_cache (EBookBackendExchange *be)
 	bepriv->is_cache_ready=TRUE;
 	e_file_cache_thaw_changes (E_FILE_CACHE (bepriv->cache));
 	UNLOCK (bepriv);
+
+	g_object_unref (be);
+
 	return NULL;
 }
 
-static gboolean
+static gpointer
 update_cache (EBookBackendExchange *be)
 {
 	EBookBackendExchangePrivate *bepriv = be->priv;
@@ -675,7 +678,10 @@ update_cache (EBookBackendExchange *be)
 	bepriv->is_cache_ready=TRUE;
 	e_file_cache_thaw_changes (E_FILE_CACHE (bepriv->cache));
 	UNLOCK (bepriv);
-	return TRUE;
+
+	g_object_unref (be);
+
+	return NULL;
 }
 
 static gboolean
@@ -2494,12 +2500,13 @@ e_book_backend_exchange_authenticate_user (EBookBackend *backend, GCancellable *
 			e_book_backend_exchange_connect (be, &error);
 		if (e_book_backend_cache_is_populated (bepriv->cache)) {
 			if (!e_book_backend_is_readonly (backend))
-				g_thread_create ((GThreadFunc) update_cache,
-						  be, FALSE, NULL);
+				if (!g_thread_create ((GThreadFunc) update_cache, g_object_ref (be), FALSE, NULL))
+					g_object_unref (be);
 		}
 		else if (!e_book_backend_is_readonly (backend) || bepriv->marked_for_offline) {
 			/* for personal books we always cache*/
-			g_thread_create ((GThreadFunc) build_cache, be, FALSE, NULL);
+			if (!g_thread_create ((GThreadFunc) build_cache, g_object_ref (be), FALSE, NULL))
+				g_object_unref (be);
 		}
 		e_book_backend_notify_opened (backend, error);
 	}
diff --git a/calendar/e-cal-backend-exchange-calendar.c b/calendar/e-cal-backend-exchange-calendar.c
index 78d87c6..b85e063 100644
--- a/calendar/e-cal-backend-exchange-calendar.c
+++ b/calendar/e-cal-backend-exchange-calendar.c
@@ -437,6 +437,7 @@ get_changed_events (ECalBackendExchange *cbex)
 		g_hash_table_destroy (modtimes);
 		g_hash_table_destroy (attachments);
 		g_mutex_unlock (cbexc->priv->mutex);
+		g_object_unref (cbexc);
 		return status;
 	}
 
@@ -452,6 +453,7 @@ get_changed_events (ECalBackendExchange *cbex)
 		g_hash_table_destroy (attachments);
 		cbexc->priv->is_loaded = TRUE;
 		g_mutex_unlock (cbexc->priv->mutex);
+		g_object_unref (cbexc);
 		return SOUP_STATUS_OK;
 	}
 
@@ -506,6 +508,7 @@ get_changed_events (ECalBackendExchange *cbex)
 		g_hash_table_destroy (modtimes);
 		g_hash_table_destroy (attachments);
 		g_mutex_unlock (cbexc->priv->mutex);
+		g_object_unref (cbexc);
 		return status;
 	}
 	if (!hrefs->len) {
@@ -514,6 +517,7 @@ get_changed_events (ECalBackendExchange *cbex)
 		g_hash_table_destroy (attachments);
 		cbexc->priv->is_loaded = TRUE;
 		g_mutex_unlock (cbexc->priv->mutex);
+		g_object_unref (cbexc);
 		return SOUP_STATUS_OK;
 	}
 
@@ -521,6 +525,7 @@ get_changed_events (ECalBackendExchange *cbex)
 	ctx = exchange_account_get_context (cbex->account);
 	if (!ctx) {
 		g_mutex_unlock (cbexc->priv->mutex);
+		g_object_unref (cbexc);
 		/* This either means we lost connection or we are in offline mode */
 		return SOUP_STATUS_CANT_CONNECT;
 	}
@@ -550,6 +555,8 @@ get_changed_events (ECalBackendExchange *cbex)
 		cbexc->priv->is_loaded = TRUE;
 
 	g_mutex_unlock (cbexc->priv->mutex);
+	g_object_unref (cbexc);
+
 	return status;
 }
 
@@ -564,7 +571,7 @@ notify_changes (E2kContext *ctx, const gchar *uri,
 	g_return_if_fail (E_IS_CAL_BACKEND_EXCHANGE (ecalbex));
 	g_return_if_fail (uri != NULL);
 
-	get_changed_events (ecalbex);
+	get_changed_events (g_object_ref (ecalbex));
 
 }
 
@@ -600,11 +607,12 @@ authenticate_user (ECalBackendSync *backend, GCancellable *cancellable, ECredent
 			E2K_CONTEXT_OBJECT_REMOVED, 30,
 			notify_changes, backend);
 
-	thread = g_thread_create ((GThreadFunc) get_changed_events, E_CAL_BACKEND_EXCHANGE (backend), FALSE, &error);
+	thread = g_thread_create ((GThreadFunc) get_changed_events, g_object_ref (backend), FALSE, &error);
 	if (!thread) {
 		g_warning (G_STRLOC ": %s", error->message);
 		g_propagate_error (perror, EDC_ERROR_EX (OtherError, error->message));
 		g_error_free (error);
+		g_object_unref (backend);
 	}
 }
 
@@ -613,7 +621,7 @@ refresh_calendar (ECalBackendSync *backend, EDataCal *cal, GCancellable *cancell
 {
 	g_return_if_fail (E_IS_CAL_BACKEND_EXCHANGE (backend));
 
-	get_changed_events (E_CAL_BACKEND_EXCHANGE (backend));
+	get_changed_events (g_object_ref (backend));
 }
 
 struct _cb_data {
diff --git a/calendar/e-cal-backend-exchange-tasks.c b/calendar/e-cal-backend-exchange-tasks.c
index 684b189..750ae1c 100644
--- a/calendar/e-cal-backend-exchange-tasks.c
+++ b/calendar/e-cal-backend-exchange-tasks.c
@@ -854,6 +854,7 @@ get_changed_tasks (ECalBackendExchange *cbex)
 		g_hash_table_destroy (modtimes);
 		g_hash_table_destroy (attachments);
 		g_mutex_unlock (cbext->priv->mutex);
+		g_object_unref (cbext);
 		return status;
 	}
 
@@ -868,6 +869,7 @@ get_changed_tasks (ECalBackendExchange *cbex)
 		g_hash_table_destroy (attachments);
 		cbext->priv->is_loaded = TRUE;
 		g_mutex_unlock (cbext->priv->mutex);
+		g_object_unref (cbext);
 		return SOUP_STATUS_OK;
 	}
 
@@ -913,6 +915,7 @@ get_changed_tasks (ECalBackendExchange *cbex)
 		g_ptr_array_free (hrefs, TRUE);
 		g_hash_table_destroy (attachments);
 		g_mutex_unlock (cbext->priv->mutex);
+		g_object_unref (cbext);
 		return status;
 	}
 
@@ -921,12 +924,14 @@ get_changed_tasks (ECalBackendExchange *cbex)
 		g_hash_table_destroy (attachments);
 		cbext->priv->is_loaded = TRUE;
 		g_mutex_unlock (cbext->priv->mutex);
+		g_object_unref (cbext);
 		return SOUP_STATUS_OK;
 	}
 
 	ctx = exchange_account_get_context (cbex->account);
 	if (!ctx) {
 		g_mutex_unlock (cbext->priv->mutex);
+		g_object_unref (cbext);
 		/* This either means we lost connection or we are in offline mode */
 		return SOUP_STATUS_CANT_CONNECT;
 	}
@@ -967,6 +972,8 @@ get_changed_tasks (ECalBackendExchange *cbex)
 		cbext->priv->is_loaded = TRUE;
 
 	g_mutex_unlock (cbext->priv->mutex);
+	g_object_unref (cbext);
+
 	return status;
 }
 
@@ -981,7 +988,7 @@ notify_changes (E2kContext *ctx, const gchar *uri,
 	g_return_if_fail (E_IS_CAL_BACKEND_EXCHANGE (ecalbex));
 	g_return_if_fail (uri != NULL);
 
-	get_changed_tasks (ecalbex);
+	get_changed_tasks (g_object_ref (ecalbex));
 
 }
 
@@ -1017,10 +1024,11 @@ authenticate_user_task (ECalBackendSync *backend, GCancellable *cancellable, ECr
 					E2K_CONTEXT_OBJECT_REMOVED, 30,
 					notify_changes, backend);
 
-	thread = g_thread_create ((GThreadFunc) get_changed_tasks, E_CAL_BACKEND_EXCHANGE (backend), FALSE, &error);
+	thread = g_thread_create ((GThreadFunc) get_changed_tasks, g_object_ref (backend), FALSE, &error);
 	if (!thread) {
 		g_propagate_error (perror, EDC_ERROR_EX (OtherError, error->message));
 		g_error_free (error);
+		g_object_unref (backend);
 	}
 }
 
@@ -1029,7 +1037,7 @@ refresh_task (ECalBackendSync *backend, EDataCal *cal, GCancellable *cancellable
 {
 	g_return_if_fail (E_IS_CAL_BACKEND_EXCHANGE (backend));
 
-	get_changed_tasks (E_CAL_BACKEND_EXCHANGE (backend));
+	get_changed_tasks (g_object_ref (backend));
 }
 
 struct _cb_data {



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