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



commit 1f674b748f81a6754eb9b882500526b4f7df2d4e
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 252d0d8..1ba80ba 100644
--- a/src/goabackend/goaewsclient.c
+++ b/src/goabackend/goaewsclient.c
@@ -93,6 +93,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 114274e..62ead76 100644
--- a/src/goabackend/goahttpclient.c
+++ b/src/goabackend/goahttpclient.c
@@ -84,6 +84,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);
@@ -154,6 +156,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;
@@ -184,8 +188,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]