[glib/cherry-pick-b17436d9] Merge branch 'wip/tingping/socketclient-cancel-2' into 'master'



commit 0195a56334a8a8872dcb9473257fcc063e642d13
Author: Michael Catanzaro <mcatanzaro posteo net>
Date:   Mon May 6 21:50:25 2019 +0000

    Merge branch 'wip/tingping/socketclient-cancel-2' into 'master'
    
    gsocketclient: Fix potential critical when cancelling connect
    
    Closes #1747
    
    See merge request GNOME/glib!783
    
    (cherry picked from commit b17436d952f5ad682dfe98e0eca7bc31705cf776)
    
    313e7cba gsocketclient: Fix potential critical when cancelling connect

 gio/gsocketclient.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/gio/gsocketclient.c b/gio/gsocketclient.c
index 9db7ca0be..97427cbf1 100644
--- a/gio/gsocketclient.c
+++ b/gio/gsocketclient.c
@@ -1426,15 +1426,24 @@ g_socket_client_async_connect_complete (GSocketClientAsyncConnectData *data)
       data->connection = (GIOStream *)wrapper_connection;
     }
 
-  if (!g_task_return_error_if_cancelled (data->task))
+  if (!data->completed)
     {
-      g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, 
data->connection);
-      g_task_return_pointer (data->task, g_steal_pointer (&data->connection), g_object_unref);
+      GError *error = NULL;
+
+      if (g_cancellable_set_error_if_cancelled (g_task_get_cancellable (data->task), &error))
+        {
+          g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, NULL);
+          g_task_return_error (data->task, g_steal_pointer (&error));
+        }
+      else
+        {
+          g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, 
data->connection);
+          g_task_return_pointer (data->task, g_steal_pointer (&data->connection), g_object_unref);
+        }
+
+      data->completed = TRUE;
     }
-  else
-    g_socket_client_emit_event (data->client, G_SOCKET_CLIENT_COMPLETE, data->connectable, NULL);
 
-  data->completed = TRUE;
   g_object_unref (data->task);
 }
 


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