[libgdata] [core] Fix a race condition crash when authenticating



commit bf2d1638914db6a028c0d414b3a0e07cffe3a06f
Author: Philip Withnall <philip tecnocode co uk>
Date:   Fri Apr 24 22:16:34 2009 +0100

    [core] Fix a race condition crash when authenticating
    
    Fixed a race condition crash when authenticating asynchronously, where the
    authentication struct would sometimes get freed before the username and
    password were saved from it.
    
    Also removed gdata-marshal.h from gdata.h.
---
 gdata/gdata-service.c |   19 ++++++++++++++-----
 gdata/gdata.h         |    1 -
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/gdata/gdata-service.c b/gdata/gdata-service.c
index 086f0ab..985b3f7 100644
--- a/gdata/gdata-service.c
+++ b/gdata/gdata-service.c
@@ -367,6 +367,8 @@ set_authentication_details_cb (AuthenticateAsyncData *data)
 	g_object_notify (service, "authenticated");
 	g_object_thaw_notify (service);
 
+	authenticate_async_data_free (data);
+
 	return FALSE;
 }
 
@@ -380,6 +382,7 @@ authenticate_thread (GSimpleAsyncResult *result, GDataService *service, GCancell
 	if (g_cancellable_set_error_if_cancelled (cancellable, &error) == TRUE) {
 		g_simple_async_result_set_from_error (result, error);
 		g_error_free (error);
+		authenticate_async_data_free (data);
 		return;
 	}
 
@@ -388,11 +391,11 @@ authenticate_thread (GSimpleAsyncResult *result, GDataService *service, GCancell
 	if (data->success == FALSE) {
 		g_simple_async_result_set_from_error (result, error);
 		g_error_free (error);
+		authenticate_async_data_free (data);
+		return;
 	}
 
-	/* Update the authentication details held by the service.
-	 * This should always be executed before the callback in g_simple_async_result_run_in_thread ---
-	 * if not, data will already have been freed, and crashage will happen. */
+	/* Update the authentication details held by the service */
 	data->service = service;
 	g_idle_add ((GSourceFunc) set_authentication_details_cb, data);
 }
@@ -430,7 +433,7 @@ gdata_service_authenticate_async (GDataService *self, const gchar *username, con
 	data->password = g_strdup (password);
 
 	result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, gdata_service_authenticate_async);
-	g_simple_async_result_set_op_res_gpointer (result, data, (GDestroyNotify) authenticate_async_data_free);
+	g_simple_async_result_set_op_res_gpointer (result, data, NULL);
 	g_simple_async_result_run_in_thread (result, (GSimpleAsyncThreadFunc) authenticate_thread, G_PRIORITY_DEFAULT, cancellable);
 	g_object_unref (result);
 }
@@ -636,7 +639,13 @@ login_error:
 	if (retval == TRUE) {
 		/* Update several properties the service holds */
 		g_free (priv->username);
-		priv->username = g_strdup (username);
+
+		/* Ensure the username is always a full e-mail address */
+		if (strchr (username, '@') == NULL)
+			priv->username = g_strdup_printf ("%s@" EMAIL_DOMAIN, username);
+		else
+			priv->username = g_strdup (username);
+
 		g_free (priv->password);
 		priv->password = g_strdup (password);
 
diff --git a/gdata/gdata.h b/gdata/gdata.h
index fc23399..8a93d45 100644
--- a/gdata/gdata.h
+++ b/gdata/gdata.h
@@ -28,7 +28,6 @@
 #include <gdata/gdata-parser.h>
 #include <gdata/gdata-query.h>
 #include <gdata/gdata-enums.h>
-#include <gdata/gdata-marshal.h>
 
 /* Namespaces */
 #include <gdata/gdata-atom.h>



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