[gnome-online-accounts] ewsclient: httpclient: Don't crash or deadlock during clean up



commit 3b35bd716dfe91ee0c1ac4b375de9dcf6e897bae
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Jan 16 15:53:59 2015 +0100

    ewsclient: httpclient: Don't crash or deadlock during clean up
    
    Clean up the SoupSession and associated data from the correct thread
    and GMainContext, and do so before completing the operation.
    
    Fixes: https://bugzilla.gnome.org/743044

 src/goabackend/goaewsclient.c  |   16 ++++++++++++++--
 src/goabackend/goahttpclient.c |   14 ++++++++++++--
 2 files changed, 26 insertions(+), 4 deletions(-)
---
diff --git a/src/goabackend/goaewsclient.c b/src/goabackend/goaewsclient.c
index af92187..df95307 100644
--- a/src/goabackend/goaewsclient.c
+++ b/src/goabackend/goaewsclient.c
@@ -91,6 +91,8 @@ ews_client_autodiscover_data_free (gpointer user_data)
 {
   AutodiscoverData *data = user_data;
 
+  g_simple_async_result_complete_in_idle (data->res);
+
   if (data->cancellable_id > 0)
     {
       g_cancellable_disconnect (data->cancellable, data->cancellable_id);
@@ -338,9 +340,19 @@ ews_client_autodiscover_response_cb (SoupSession *session, SoupMessage *msg, gpo
   data->pending--;
   if (data->pending == 0)
     {
+      GMainContext *context;
+      GSource *source;
+
       g_simple_async_result_set_op_res_gboolean (data->res, op_res);
-      g_simple_async_result_complete_in_idle (data->res);
-      g_idle_add (ews_client_autodiscover_data_free, data);
+
+      source = g_idle_source_new ();
+      g_source_set_priority (source, G_PRIORITY_DEFAULT_IDLE);
+      g_source_set_callback (source, ews_client_autodiscover_data_free, data, NULL);
+      g_source_set_name (source, "[goa] ews_client_autodiscover_data_free");
+
+      context = g_main_context_get_thread_default ();
+      g_source_attach (source, context);
+      g_source_unref (source);
     }
 }
 
diff --git a/src/goabackend/goahttpclient.c b/src/goabackend/goahttpclient.c
index 0cc041b..336f623 100644
--- a/src/goabackend/goahttpclient.c
+++ b/src/goabackend/goahttpclient.c
@@ -82,6 +82,8 @@ http_client_check_data_free (gpointer user_data)
 {
   CheckData *data = user_data;
 
+  g_simple_async_result_complete_in_idle (data->res);
+
   if (data->cancellable_id > 0)
     {
       g_cancellable_disconnect (data->cancellable, data->cancellable_id);
@@ -152,6 +154,8 @@ http_client_check_response_cb (SoupSession *session, SoupMessage *msg, gpointer
 {
   GError *error;
   CheckData *data = user_data;
+  GMainContext *context;
+  GSource *source;
   gboolean op_res;
 
   error = NULL;
@@ -182,8 +186,14 @@ http_client_check_response_cb (SoupSession *session, SoupMessage *msg, gpointer
   if (error != NULL)
     g_simple_async_result_take_error (data->res, error);
 
-  g_simple_async_result_complete_in_idle (data->res);
-  g_idle_add (http_client_check_data_free, data);
+  source = g_idle_source_new ();
+  g_source_set_priority (source, G_PRIORITY_DEFAULT_IDLE);
+  g_source_set_callback (source, http_client_check_data_free, data, NULL);
+  g_source_set_name (source, "[goa] http_client_check_data_free");
+
+  context = g_main_context_get_thread_default ();
+  g_source_attach (source, context);
+  g_source_unref (source);
 }
 
 static void


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