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



commit f17af3f38e0a300e55486d0b9d65e13a538b26c4
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 0c787c2..46e16e2 100644
--- a/src/goabackend/goaewsclient.c
+++ b/src/goabackend/goaewsclient.c
@@ -96,6 +96,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);
@@ -340,9 +342,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 9ca922a..6b1c635 100644
--- a/src/goabackend/goahttpclient.c
+++ b/src/goabackend/goahttpclient.c
@@ -87,6 +87,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);
@@ -157,6 +159,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;
@@ -187,8 +191,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]