[evolution-data-server] Use camel_service_ref_session().



commit 4dbff3ebe13709121d270ea8def4daa502fa1206
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Feb 11 08:07:52 2013 -0500

    Use camel_service_ref_session().

 camel/camel-disco-diary.c                   |   17 ++++++++++++++---
 camel/camel-disco-folder.c                  |    4 +++-
 camel/camel-disco-store.c                   |   20 +++++++++++++++-----
 camel/camel-folder-summary.c                |   12 ++++++++----
 camel/camel-folder.c                        |   22 +++++++++++++++-------
 camel/camel-imapx-server.c                  |    3 ++-
 camel/camel-imapx-store.c                   |    8 ++++++--
 camel/camel-network-service.c               |    4 +++-
 camel/camel-offline-folder.c                |    4 +++-
 camel/camel-offline-store.c                 |   11 ++++++++---
 camel/camel-sasl-popb4smtp.c                |    4 +++-
 camel/camel-service.c                       |   17 ++++++++++++-----
 camel/camel-session.c                       |    3 ---
 camel/camel-store.c                         |   16 ++++++++++++----
 camel/camel-subscribable.c                  |    8 ++++++--
 camel/camel-vee-folder.c                    |    4 +++-
 camel/camel-vee-store.c                     |    6 +++++-
 camel/providers/nntp/camel-nntp-store.c     |   26 +++++++++++++++++---------
 camel/providers/pop3/camel-pop3-store.c     |    4 +++-
 camel/providers/smtp/camel-smtp-transport.c |    4 +++-
 20 files changed, 141 insertions(+), 56 deletions(-)
---
diff --git a/camel/camel-disco-diary.c b/camel/camel-disco-diary.c
index 2be544c..fc14c97 100644
--- a/camel/camel-disco-diary.c
+++ b/camel/camel-disco-diary.c
@@ -201,7 +201,7 @@ camel_disco_diary_log (CamelDiscoDiary *diary,
 		gchar *msg;
 
 		service = CAMEL_SERVICE (diary->store);
-		session = camel_service_get_session (service);
+		session = camel_service_ref_session (service);
 
 		msg = g_strdup_printf (
 			_("Could not write log entry: %s\n"
@@ -213,6 +213,8 @@ camel_disco_diary_log (CamelDiscoDiary *diary,
 			session, CAMEL_SESSION_ALERT_ERROR, msg, NULL, NULL);
 		g_free (msg);
 
+		g_object_unref (session);
+
 		fclose (diary->file);
 		diary->file = NULL;
 	}
@@ -267,17 +269,26 @@ diary_decode_folder (CamelDiscoDiary *diary,
 		if (folder)
 			g_hash_table_insert (diary->folders, name, folder);
 		else {
+			CamelService *service;
+			CamelSession *session;
+
+			service = CAMEL_SERVICE (diary->store);
+			session = camel_service_ref_session (service);
+
 			msg = g_strdup_printf (
 				_("Could not open '%s':\n%s\n"
 				"Changes made to this folder "
 				"will not be resynchronized."),
 				name, error->message);
-			g_error_free (error);
 			camel_session_alert_user (
-				camel_service_get_session (CAMEL_SERVICE (diary->store)),
+				session,
 				CAMEL_SESSION_ALERT_WARNING,
 				msg, NULL, cancellable);
 			g_free (msg);
+
+			g_object_unref (session);
+			g_error_free (error);
+
 			g_free (name);
 		}
 	} else
diff --git a/camel/camel-disco-folder.c b/camel/camel-disco-folder.c
index ee72f8a..0caa67a 100644
--- a/camel/camel-disco-folder.c
+++ b/camel/camel-disco-folder.c
@@ -112,7 +112,7 @@ cdf_folder_changed (CamelFolder *folder,
 	parent_store = camel_folder_get_parent_store (folder);
 
 	service = CAMEL_SERVICE (parent_store);
-	session = camel_service_get_session (service);
+	session = camel_service_ref_session (service);
 
 	sync_folder = camel_disco_folder_get_offline_sync (
 		CAMEL_DISCO_FOLDER (folder));
@@ -137,6 +137,8 @@ cdf_folder_changed (CamelFolder *folder,
 			(CamelSessionCallback) cdf_sync_offline,
 			data, (GDestroyNotify) cdf_sync_free);
 	}
+
+	g_object_unref (session);
 }
 
 static void
diff --git a/camel/camel-disco-store.c b/camel/camel-disco-store.c
index 60a0fd6..61c467e 100644
--- a/camel/camel-disco-store.c
+++ b/camel/camel-disco-store.c
@@ -68,7 +68,7 @@ disco_store_constructed (GObject *object)
 	G_OBJECT_CLASS (camel_disco_store_parent_class)->constructed (object);
 
 	service = CAMEL_SERVICE (object);
-	session = camel_service_get_session (service);
+	session = camel_service_ref_session (service);
 
 	if (camel_session_get_online (session))
 		disco->status = CAMEL_DISCO_STORE_ONLINE;
@@ -78,6 +78,8 @@ disco_store_constructed (GObject *object)
 	g_signal_connect (
 		service, "notify::connection-status",
 		G_CALLBACK (disco_store_update_status), NULL);
+
+	g_object_unref (session);
 }
 
 static gboolean
@@ -283,9 +285,11 @@ disco_store_set_status (CamelDiscoStore *disco_store,
 
 	store = CAMEL_STORE (disco_store);
 	service = CAMEL_SERVICE (disco_store);
-	session = camel_service_get_session (service);
 
+	session = camel_service_ref_session (service);
 	network_available = camel_session_get_network_available (session);
+	g_object_unref (session);
+
 	store_is_online = (disco_store->status == CAMEL_DISCO_STORE_ONLINE);
 	going_offline = (status == CAMEL_DISCO_STORE_OFFLINE);
 
@@ -384,12 +388,14 @@ camel_disco_store_status (CamelDiscoStore *store)
 		CAMEL_IS_DISCO_STORE (store), CAMEL_DISCO_STORE_ONLINE);
 
 	service = CAMEL_SERVICE (store);
-	session = camel_service_get_session (service);
+	session = camel_service_ref_session (service);
 
 	if (store->status != CAMEL_DISCO_STORE_OFFLINE
 	    && !camel_session_get_online (session))
 		store->status = CAMEL_DISCO_STORE_OFFLINE;
 
+	g_object_unref (session);
+
 	return store->status;
 }
 
@@ -480,6 +486,7 @@ camel_disco_store_prepare_for_offline (CamelDiscoStore *disco_store,
 	CamelService *service;
 	CamelSession *session;
 	CamelSettings *settings;
+	gboolean network_available;
 	gboolean store_is_online;
 	gboolean sync_store;
 
@@ -487,10 +494,13 @@ camel_disco_store_prepare_for_offline (CamelDiscoStore *disco_store,
 
 	store = CAMEL_STORE (disco_store);
 	service = CAMEL_SERVICE (disco_store);
-	session = camel_service_get_session (service);
+
+	session = camel_service_ref_session (service);
+	network_available = camel_session_get_network_available (session);
+	g_object_unref (session);
 
 	/* We can't prepare for offline if we're already offline. */
-	if (!camel_session_get_network_available (session))
+	if (!network_available)
 		return;
 
 	/* Sync the folder fully if we've been told to
diff --git a/camel/camel-folder-summary.c b/camel/camel-folder-summary.c
index 455289c..887afd4 100644
--- a/camel/camel-folder-summary.c
+++ b/camel/camel-folder-summary.c
@@ -2118,18 +2118,20 @@ cfs_try_release_memory (CamelFolderSummary *summary)
 		return FALSE;
 	}
 
-	parent_store = camel_folder_get_parent_store (summary->priv->folder);
-	session = camel_service_get_session (CAMEL_SERVICE (parent_store));
-
 	if (time (NULL) - summary->priv->cache_load_time < SUMMARY_CACHE_DROP)
 		return TRUE;
 
+	parent_store = camel_folder_get_parent_store (summary->priv->folder);
+	session = camel_service_ref_session (CAMEL_SERVICE (parent_store));
+
 	camel_session_submit_job (
 		session,
 		(CamelSessionCallback) remove_cache,
 		g_object_ref (summary),
 		(GDestroyNotify) g_object_unref);
 
+	g_object_unref (session);
+
 	return TRUE;
 }
 
@@ -2301,7 +2303,7 @@ cfs_reload_from_db (CamelFolderSummary *summary,
 
 	folder_name = camel_folder_get_full_name (summary->priv->folder);
 	parent_store = camel_folder_get_parent_store (summary->priv->folder);
-	session = camel_service_get_session (CAMEL_SERVICE (parent_store));
+	session = camel_service_ref_session (CAMEL_SERVICE (parent_store));
 	cdb = parent_store->cdb_r;
 
 	data.columns_hash = NULL;
@@ -2324,6 +2326,8 @@ cfs_reload_from_db (CamelFolderSummary *summary,
 			g_object_ref (summary->priv->folder),
 			(GDestroyNotify) g_object_unref);
 
+	g_object_unref (session);
+
 	return ret == 0 ? 0 : -1;
 }
 
diff --git a/camel/camel-folder.c b/camel/camel-folder.c
index 79ebdbc..e2470d8 100644
--- a/camel/camel-folder.c
+++ b/camel/camel-folder.c
@@ -1662,10 +1662,6 @@ folder_changed (CamelFolder *folder,
 
 	g_return_if_fail (info != NULL);
 
-	parent_store = camel_folder_get_parent_store (folder);
-	session = camel_service_get_session (CAMEL_SERVICE (parent_store));
-	junk_filter = camel_session_get_junk_filter (session);
-
 	camel_folder_lock (folder, CAMEL_FOLDER_CHANGE_LOCK);
 	if (folder->priv->frozen) {
 		camel_folder_change_info_cat (folder->priv->changed_frozen, info);
@@ -1675,6 +1671,10 @@ folder_changed (CamelFolder *folder,
 	}
 	camel_folder_unlock (folder, CAMEL_FOLDER_CHANGE_LOCK);
 
+	parent_store = camel_folder_get_parent_store (folder);
+	session = camel_service_ref_session (CAMEL_SERVICE (parent_store));
+	junk_filter = camel_session_get_junk_filter (session);
+
 	if (junk_filter != NULL && info->uid_changed->len) {
 		CamelMessageFlags flags;
 
@@ -1738,6 +1738,8 @@ folder_changed (CamelFolder *folder,
 
 		g_signal_stop_emission (folder, signals[CHANGED], 0);
 	}
+
+	g_object_unref (session);
 }
 
 static void
@@ -2922,7 +2924,7 @@ camel_folder_delete (CamelFolder *folder)
 	camel_db_delete_folder (parent_store->cdb_w, full_name, NULL);
 
 	service = CAMEL_SERVICE (parent_store);
-	session = camel_service_get_session (service);
+	session = camel_service_ref_session (service);
 
 	signal_data = g_slice_new0 (SignalData);
 	signal_data->folder = g_object_ref (folder);
@@ -2932,6 +2934,8 @@ camel_folder_delete (CamelFolder *folder)
 		session, G_PRIORITY_HIGH_IDLE,
 		folder_emit_deleted_cb,
 		signal_data, (GDestroyNotify) signal_data_free);
+
+	g_object_unref (session);
 }
 
 /**
@@ -2972,7 +2976,7 @@ camel_folder_rename (CamelFolder *folder,
 	camel_db_rename_folder (parent_store->cdb_w, old_name, new_name, NULL);
 
 	service = CAMEL_SERVICE (parent_store);
-	session = camel_service_get_session (service);
+	session = camel_service_ref_session (service);
 
 	signal_data = g_slice_new0 (SignalData);
 	signal_data->folder = g_object_ref (folder);
@@ -2983,6 +2987,8 @@ camel_folder_rename (CamelFolder *folder,
 		session, G_PRIORITY_HIGH_IDLE,
 		folder_emit_renamed_cb,
 		signal_data, (GDestroyNotify) signal_data_free);
+
+	g_object_unref (session);
 }
 
 /**
@@ -3030,7 +3036,7 @@ camel_folder_changed (CamelFolder *folder,
 		parent_store = camel_folder_get_parent_store (folder);
 
 		service = CAMEL_SERVICE (parent_store);
-		session = camel_service_get_session (service);
+		session = camel_service_ref_session (service);
 
 		pending_changes = camel_folder_change_info_new ();
 		folder->priv->pending_changes = pending_changes;
@@ -3042,6 +3048,8 @@ camel_folder_changed (CamelFolder *folder,
 			session, G_PRIORITY_LOW,
 			folder_emit_changed_cb,
 			signal_data, (GDestroyNotify) signal_data_free);
+
+		g_object_unref (session);
 	}
 
 	camel_folder_change_info_cat (pending_changes, changes);
diff --git a/camel/camel-imapx-server.c b/camel/camel-imapx-server.c
index 86f2b71..33d5618 100644
--- a/camel/camel-imapx-server.c
+++ b/camel/camel-imapx-server.c
@@ -4093,7 +4093,7 @@ imapx_reconnect (CamelIMAPXServer *is,
 	store = camel_imapx_server_ref_store (is);
 
 	service = CAMEL_SERVICE (store);
-	session = camel_service_get_session (service);
+	session = camel_service_ref_session (service);
 
 	settings = camel_service_ref_settings (service);
 
@@ -4200,6 +4200,7 @@ exception:
 exit:
 	g_free (mechanism);
 
+	g_object_unref (session);
 	g_object_unref (store);
 
 	return success;
diff --git a/camel/camel-imapx-store.c b/camel/camel-imapx-store.c
index 0c7650b..ae859a3 100644
--- a/camel/camel-imapx-store.c
+++ b/camel/camel-imapx-store.c
@@ -1340,14 +1340,12 @@ imapx_store_get_folder_info_sync (CamelStore *store,
 	CamelIMAPXStore *istore = (CamelIMAPXStore *) store;
 	CamelFolderInfo * fi= NULL;
 	CamelService *service;
-	CamelSession *session;
 	CamelSettings *settings;
 	gboolean initial_setup = FALSE;
 	gboolean use_subscriptions;
 	gchar *pattern;
 
 	service = CAMEL_SERVICE (store);
-	session = camel_service_get_session (service);
 
 	settings = camel_service_ref_settings (service);
 
@@ -1375,13 +1373,19 @@ imapx_store_get_folder_info_sync (CamelStore *store,
 		time_t now = time (NULL);
 
 		if (now - istore->last_refresh_time > FINFO_REFRESH_INTERVAL) {
+			CamelSession *session;
+
 			istore->last_refresh_time = time (NULL);
 
+			session = camel_service_ref_session (service);
+
 			camel_session_submit_job (
 				session, (CamelSessionCallback)
 				imapx_refresh_finfo,
 				g_object_ref (store),
 				(GDestroyNotify) g_object_unref);
+
+			g_object_unref (session);
 		}
 
 		fi = get_folder_info_offline (store, top, flags, error);
diff --git a/camel/camel-network-service.c b/camel/camel-network-service.c
index 8555d25..fbf4392 100644
--- a/camel/camel-network-service.c
+++ b/camel/camel-network-service.c
@@ -52,7 +52,7 @@ network_service_connect_sync (CamelNetworkService *service,
 	gchar *host;
 	gint status;
 
-	session = camel_service_get_session (CAMEL_SERVICE (service));
+	session = camel_service_ref_session (CAMEL_SERVICE (service));
 	settings = camel_service_ref_settings (CAMEL_SERVICE (service));
 	g_return_val_if_fail (CAMEL_IS_NETWORK_SETTINGS (settings), NULL);
 
@@ -119,6 +119,8 @@ network_service_connect_sync (CamelNetworkService *service,
 
 	g_free (host);
 
+	g_object_unref (session);
+
 	return stream;
 }
 
diff --git a/camel/camel-offline-folder.c b/camel/camel-offline-folder.c
index 139a0ee..515311d 100644
--- a/camel/camel-offline-folder.c
+++ b/camel/camel-offline-folder.c
@@ -134,7 +134,7 @@ offline_folder_changed (CamelFolder *folder,
 	parent_store = camel_folder_get_parent_store (folder);
 
 	service = CAMEL_SERVICE (parent_store);
-	session = camel_service_get_session (service);
+	session = camel_service_ref_session (service);
 
 	settings = camel_service_ref_settings (service);
 
@@ -159,6 +159,8 @@ offline_folder_changed (CamelFolder *folder,
 			offline_folder_downsync_background, data,
 			(GDestroyNotify) offline_downsync_data_free);
 	}
+
+	g_object_unref (session);
 }
 
 static void
diff --git a/camel/camel-offline-store.c b/camel/camel-offline-store.c
index f54df73..b4e8050 100644
--- a/camel/camel-offline-store.c
+++ b/camel/camel-offline-store.c
@@ -54,8 +54,9 @@ offline_store_constructed (GObject *object)
 	G_OBJECT_CLASS (camel_offline_store_parent_class)->
 		constructed (object);
 
-	session = camel_service_get_session (CAMEL_SERVICE (object));
+	session = camel_service_ref_session (CAMEL_SERVICE (object));
 	priv->online = camel_session_get_online (session);
+	g_object_unref (session);
 }
 
 static void
@@ -124,7 +125,7 @@ camel_offline_store_set_online_sync (CamelOfflineStore *store,
 		return TRUE;
 
 	service = CAMEL_SERVICE (store);
-	session = camel_service_get_session (service);
+	session = camel_service_ref_session (service);
 
 	network_available = camel_session_get_network_available (session);
 	store_is_online = camel_offline_store_get_online (store);
@@ -136,6 +137,8 @@ camel_offline_store_set_online_sync (CamelOfflineStore *store,
 
 	g_object_unref (settings);
 
+	g_object_unref (session);
+
 	/* Returning to online mode is the simpler case. */
 	if (!store_is_online) {
 		store->priv->online = online;
@@ -203,7 +206,7 @@ camel_offline_store_prepare_for_offline_sync (CamelOfflineStore *store,
 	g_return_val_if_fail (CAMEL_IS_OFFLINE_STORE (store), FALSE);
 
 	service = CAMEL_SERVICE (store);
-	session = camel_service_get_session (service);
+	session = camel_service_ref_session (service);
 
 	network_available = camel_session_get_network_available (session);
 	store_is_online = camel_offline_store_get_online (store);
@@ -215,6 +218,8 @@ camel_offline_store_prepare_for_offline_sync (CamelOfflineStore *store,
 
 	g_object_unref (settings);
 
+	g_object_unref (session);
+
 	if (network_available && store_is_online) {
 		GPtrArray *folders;
 		guint ii;
diff --git a/camel/camel-sasl-popb4smtp.c b/camel/camel-sasl-popb4smtp.c
index fcb59fb..5b3c4a5 100644
--- a/camel/camel-sasl-popb4smtp.c
+++ b/camel/camel-sasl-popb4smtp.c
@@ -76,7 +76,7 @@ sasl_popb4smtp_challenge_sync (CamelSasl *sasl,
 	gchar *pop_uid;
 
 	service = camel_sasl_get_service (sasl);
-	session = camel_service_get_session (service);
+	session = camel_service_ref_session (service);
 
 	camel_sasl_set_authenticated (sasl, FALSE);
 
@@ -89,6 +89,8 @@ sasl_popb4smtp_challenge_sync (CamelSasl *sasl,
 	else
 		service = NULL;
 
+	g_object_unref (session);
+
 	if (service == NULL) {
 		g_set_error (
 			error, CAMEL_SERVICE_ERROR,
diff --git a/camel/camel-service.c b/camel/camel-service.c
index 845a06d..b63ba9f 100644
--- a/camel/camel-service.c
+++ b/camel/camel-service.c
@@ -322,7 +322,6 @@ service_find_old_data_dir (CamelService *service)
 	gchar *old_data_dir;
 
 	provider = camel_service_get_provider (service);
-	session = camel_service_get_session (service);
 	url = camel_service_new_camel_url (service);
 
 	allows_host = CAMEL_PROVIDER_ALLOWS (provider, CAMEL_URL_PART_HOST);
@@ -376,9 +375,13 @@ service_find_old_data_dir (CamelService *service)
 		g_string_append (path, url->path);
 	}
 
+	session = camel_service_ref_session (service);
+
 	base_dir = camel_session_get_user_data_dir (session);
 	old_data_dir = g_build_filename (base_dir, path->str, NULL);
 
+	g_object_unref (session);
+
 	g_string_free (path, TRUE);
 
 	if (!g_file_test (old_data_dir, G_FILE_TEST_IS_DIR)) {
@@ -406,7 +409,7 @@ service_queue_notify_connection_status (CamelService *service)
 {
 	CamelSession *session;
 
-	session = camel_service_get_session (service);
+	session = camel_service_ref_session (service);
 
 	/* Prioritize ahead of GTK+ redraws. */
 	camel_session_idle_add (
@@ -414,6 +417,8 @@ service_queue_notify_connection_status (CamelService *service)
 		service_notify_connection_status_cb,
 		g_object_ref (service),
 		(GDestroyNotify) g_object_unref);
+
+	g_object_unref (session);
 }
 
 static void
@@ -610,8 +615,8 @@ service_get_property (GObject *object,
 			return;
 
 		case PROP_SESSION:
-			g_value_set_object (
-				value, camel_service_get_session (
+			g_value_take_object (
+				value, camel_service_ref_session (
 				CAMEL_SERVICE (object)));
 			return;
 
@@ -688,7 +693,7 @@ service_constructed (GObject *object)
 	G_OBJECT_CLASS (camel_service_parent_class)->constructed (object);
 
 	service = CAMEL_SERVICE (object);
-	session = camel_service_get_session (service);
+	session = camel_service_ref_session (service);
 
 	uid = camel_service_get_uid (service);
 
@@ -697,6 +702,8 @@ service_constructed (GObject *object)
 
 	base_dir = camel_session_get_user_cache_dir (session);
 	service->priv->user_cache_dir = g_build_filename (base_dir, uid, NULL);
+
+	g_object_unref (session);
 }
 
 static gchar *
diff --git a/camel/camel-session.c b/camel/camel-session.c
index 975d707..e335814 100644
--- a/camel/camel-session.c
+++ b/camel/camel-session.c
@@ -992,9 +992,6 @@ camel_session_remove_service (CamelSession *session,
 	g_return_if_fail (CAMEL_IS_SESSION (session));
 	g_return_if_fail (CAMEL_IS_SERVICE (service));
 
-	/* Verify the service belongs to this session. */
-	g_return_if_fail (camel_service_get_session (service) == session);
-
 	class = CAMEL_SESSION_GET_CLASS (session);
 	g_return_if_fail (class->remove_service != NULL);
 
diff --git a/camel/camel-store.c b/camel/camel-store.c
index dab6b17..f9c96d9 100644
--- a/camel/camel-store.c
+++ b/camel/camel-store.c
@@ -1273,7 +1273,7 @@ camel_store_folder_created (CamelStore *store,
 	g_return_if_fail (CAMEL_IS_STORE (store));
 	g_return_if_fail (folder_info != NULL);
 
-	session = camel_service_get_session (CAMEL_SERVICE (store));
+	session = camel_service_ref_session (CAMEL_SERVICE (store));
 
 	signal_data = g_slice_new0 (SignalData);
 	signal_data->store = g_object_ref (store);
@@ -1284,6 +1284,8 @@ camel_store_folder_created (CamelStore *store,
 		session, G_PRIORITY_HIGH_IDLE,
 		store_emit_folder_created_cb,
 		signal_data, (GDestroyNotify) signal_data_free);
+
+	g_object_unref (session);
 }
 
 /**
@@ -1308,7 +1310,7 @@ camel_store_folder_deleted (CamelStore *store,
 	g_return_if_fail (CAMEL_IS_STORE (store));
 	g_return_if_fail (folder_info != NULL);
 
-	session = camel_service_get_session (CAMEL_SERVICE (store));
+	session = camel_service_ref_session (CAMEL_SERVICE (store));
 
 	signal_data = g_slice_new0 (SignalData);
 	signal_data->store = g_object_ref (store);
@@ -1319,6 +1321,8 @@ camel_store_folder_deleted (CamelStore *store,
 		session, G_PRIORITY_HIGH_IDLE,
 		store_emit_folder_deleted_cb,
 		signal_data, (GDestroyNotify) signal_data_free);
+
+	g_object_unref (session);
 }
 
 /**
@@ -1343,7 +1347,7 @@ camel_store_folder_opened (CamelStore *store,
 	g_return_if_fail (CAMEL_IS_STORE (store));
 	g_return_if_fail (CAMEL_IS_FOLDER (folder));
 
-	session = camel_service_get_session (CAMEL_SERVICE (store));
+	session = camel_service_ref_session (CAMEL_SERVICE (store));
 
 	signal_data = g_slice_new0 (SignalData);
 	signal_data->store = g_object_ref (store);
@@ -1354,6 +1358,8 @@ camel_store_folder_opened (CamelStore *store,
 		session, G_PRIORITY_HIGH_IDLE,
 		store_emit_folder_opened_cb,
 		signal_data, (GDestroyNotify) signal_data_free);
+
+	g_object_unref (session);
 }
 
 /**
@@ -1381,7 +1387,7 @@ camel_store_folder_renamed (CamelStore *store,
 	g_return_if_fail (old_name != NULL);
 	g_return_if_fail (folder_info != NULL);
 
-	session = camel_service_get_session (CAMEL_SERVICE (store));
+	session = camel_service_ref_session (CAMEL_SERVICE (store));
 
 	signal_data = g_slice_new0 (SignalData);
 	signal_data->store = g_object_ref (store);
@@ -1393,6 +1399,8 @@ camel_store_folder_renamed (CamelStore *store,
 		session, G_PRIORITY_HIGH_IDLE,
 		store_emit_folder_renamed_cb,
 		signal_data, (GDestroyNotify) signal_data_free);
+
+	g_object_unref (session);
 }
 
 static void
diff --git a/camel/camel-subscribable.c b/camel/camel-subscribable.c
index ef14132..331103e 100644
--- a/camel/camel-subscribable.c
+++ b/camel/camel-subscribable.c
@@ -629,7 +629,7 @@ camel_subscribable_folder_subscribed (CamelSubscribable *subscribable,
 	g_return_if_fail (folder_info != NULL);
 
 	service = CAMEL_SERVICE (subscribable);
-	session = camel_service_get_session (service);
+	session = camel_service_ref_session (service);
 
 	signal_data = g_slice_new0 (SignalData);
 	signal_data->subscribable = g_object_ref (subscribable);
@@ -640,6 +640,8 @@ camel_subscribable_folder_subscribed (CamelSubscribable *subscribable,
 		session, G_PRIORITY_HIGH_IDLE,
 		subscribable_emit_folder_subscribed_cb,
 		signal_data, (GDestroyNotify) signal_data_free);
+
+	g_object_unref (session);
 }
 
 /**
@@ -666,7 +668,7 @@ camel_subscribable_folder_unsubscribed (CamelSubscribable *subscribable,
 	g_return_if_fail (folder_info != NULL);
 
 	service = CAMEL_SERVICE (subscribable);
-	session = camel_service_get_session (service);
+	session = camel_service_ref_session (service);
 
 	signal_data = g_slice_new0 (SignalData);
 	signal_data->subscribable = g_object_ref (subscribable);
@@ -677,5 +679,7 @@ camel_subscribable_folder_unsubscribed (CamelSubscribable *subscribable,
 		session, G_PRIORITY_HIGH_IDLE,
 		subscribable_emit_folder_unsubscribed_cb,
 		signal_data, (GDestroyNotify) signal_data_free);
+
+	g_object_unref (session);
 }
 
diff --git a/camel/camel-vee-folder.c b/camel/camel-vee-folder.c
index 9e77460..1e870d5 100644
--- a/camel/camel-vee-folder.c
+++ b/camel/camel-vee-folder.c
@@ -1105,7 +1105,7 @@ vee_folder_folder_changed (CamelVeeFolder *vee_folder,
 
 	folder = CAMEL_FOLDER (vee_folder);
 	parent_store = camel_folder_get_parent_store (folder);
-	session = camel_service_get_session (CAMEL_SERVICE (parent_store));
+	session = camel_service_ref_session (CAMEL_SERVICE (parent_store));
 
 	g_async_queue_lock (vee_folder->priv->change_queue);
 
@@ -1123,6 +1123,8 @@ vee_folder_folder_changed (CamelVeeFolder *vee_folder,
 	}
 
 	g_async_queue_unlock (vee_folder->priv->change_queue);
+
+	g_object_unref (session);
 }
 
 static void
diff --git a/camel/camel-vee-store.c b/camel/camel-vee-store.c
index 5cd8a63..8250f69 100644
--- a/camel/camel-vee-store.c
+++ b/camel/camel-vee-store.c
@@ -1013,15 +1013,19 @@ camel_vee_store_rebuild_unmatched_folder (CamelVeeStore *vstore,
 	/* this operation requires cancellable, thus if called
 	 * without it then run in a dedicated thread */
 	if (!cancellable) {
+		CamelService *service;
 		CamelSession *session;
 
-		session = camel_service_get_session (CAMEL_SERVICE (vstore));
+		service = CAMEL_SERVICE (vstore);
+		session = camel_service_ref_session (service);
 
 		camel_session_submit_job (
 			session, (CamelSessionCallback)
 			vee_store_rebuild_unmatched_folder,
 			g_object_ref (vstore),
 			g_object_unref);
+
+		g_object_unref (session);
 	} else {
 		vee_store_rebuild_unmatched_folder (NULL, cancellable, vstore, error);
 	}
diff --git a/camel/providers/nntp/camel-nntp-store.c b/camel/providers/nntp/camel-nntp-store.c
index 3b01b03..af02279 100644
--- a/camel/providers/nntp/camel-nntp-store.c
+++ b/camel/providers/nntp/camel-nntp-store.c
@@ -258,7 +258,7 @@ connect_to_server (CamelService *service,
 	guint len;
 	gchar *host, *path, *user, *mechanism;
 
-	session = camel_service_get_session (service);
+	session = camel_service_ref_session (service);
 	user_cache_dir = camel_service_get_user_cache_dir (service);
 
 	settings = camel_service_ref_settings (service);
@@ -345,6 +345,8 @@ fail:
 	g_free (user);
 	g_free (mechanism);
 
+	g_object_unref (session);
+
 	return retval;
 }
 
@@ -1677,7 +1679,7 @@ camel_nntp_raw_command_auth (CamelNNTPStore *store,
 	va_list ap;
 
 	service = CAMEL_SERVICE (store);
-	session = camel_service_get_session (service);
+	session = camel_service_ref_session (service);
 
 	retry = 0;
 
@@ -1690,13 +1692,15 @@ camel_nntp_raw_command_auth (CamelNNTPStore *store,
 		va_end (ap);
 
 		if (ret == NNTP_AUTH_REQUIRED) {
-			if (!camel_session_authenticate_sync (
-				session, service, NULL, cancellable, error))
-				return -1;
-			go = TRUE;
+			go = camel_session_authenticate_sync (
+				session, service, NULL, cancellable, error);
+			if (!go)
+				ret = -1;
 		}
 	} while (retry < 3 && go);
 
+	g_object_unref (session);
+
 	return ret;
 }
 
@@ -1711,6 +1715,7 @@ camel_nntp_command (CamelNNTPStore *store,
 {
 	CamelService *service;
 	CamelSession *session;
+	gboolean success;
 	const gchar *full_name = NULL;
 	const guchar *p;
 	va_list ap;
@@ -1719,7 +1724,6 @@ camel_nntp_command (CamelNNTPStore *store,
 	GError *local_error = NULL;
 
 	service = CAMEL_SERVICE (store);
-	session = camel_service_get_session (service);
 
 	if (((CamelDiscoStore *) store)->status == CAMEL_DISCO_STORE_OFFLINE) {
 		g_set_error (
@@ -1773,8 +1777,12 @@ camel_nntp_command (CamelNNTPStore *store,
 	error:
 		switch (ret) {
 		case NNTP_AUTH_REQUIRED:
-			if (!camel_session_authenticate_sync (
-				session, service, NULL, cancellable, error))
+			session = camel_service_ref_session (service);
+			success = camel_session_authenticate_sync (
+				session, service, NULL, cancellable, error);
+			g_object_unref (session);
+
+			if (!success)
 				return -1;
 			retry--;
 			ret = -1;
diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c
index 866b79b..25eaca0 100644
--- a/camel/providers/pop3/camel-pop3-store.c
+++ b/camel/providers/pop3/camel-pop3-store.c
@@ -407,7 +407,7 @@ pop3_store_connect_sync (CamelService *service,
 	gboolean success = TRUE;
 	gchar *mechanism;
 
-	session = camel_service_get_session (service);
+	session = camel_service_ref_session (service);
 	user_data_dir = camel_service_get_user_data_dir (service);
 
 	settings = camel_service_ref_settings (service);
@@ -459,6 +459,8 @@ pop3_store_connect_sync (CamelService *service,
 exit:
 	g_free (mechanism);
 
+	g_object_unref (session);
+
 	return success;
 }
 
diff --git a/camel/providers/smtp/camel-smtp-transport.c b/camel/providers/smtp/camel-smtp-transport.c
index a107525..f5f7e4c 100644
--- a/camel/providers/smtp/camel-smtp-transport.c
+++ b/camel/providers/smtp/camel-smtp-transport.c
@@ -365,7 +365,7 @@ smtp_transport_connect_sync (CamelService *service,
 	if (auth_required) {
 		CamelSession *session;
 
-		session = camel_service_get_session (service);
+		session = camel_service_ref_session (service);
 
 		if (g_hash_table_lookup (transport->authtypes, mechanism)) {
 			success = camel_session_authenticate_sync (
@@ -380,6 +380,8 @@ smtp_transport_connect_sync (CamelService *service,
 			success = FALSE;
 		}
 
+		g_object_unref (session);
+
 		if (!success)
 			camel_service_disconnect_sync (
 				service, TRUE, cancellable, NULL);


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