[gdm/gnome-3-18] session: Cancel worker proxy async ops when freeing conversations



commit f3f7d09e0557bf52bccb58a4323c5fe2db32ecd1
Author: Rui Matos <tiagomatos gmail com>
Date:   Sun Nov 15 14:07:53 2015 -0500

    session: Cancel worker proxy async ops when freeing conversations
    
    We need to cancel ongoing async ops for worker proxies when freeing
    conversations or we'll crash when the completion handler runs and we
    access free'd memory.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=758032

 daemon/gdm-session.c |   36 +++++++++++++++++++++++-------------
 1 files changed, 23 insertions(+), 13 deletions(-)
---
diff --git a/daemon/gdm-session.c b/daemon/gdm-session.c
index 72f79cd..5707b15 100644
--- a/daemon/gdm-session.c
+++ b/daemon/gdm-session.c
@@ -73,6 +73,7 @@ typedef struct
         GDBusMethodInvocation *pending_invocation;
         GdmDBusWorkerManager  *worker_manager_interface;
         GdmDBusWorker         *worker_proxy;
+        GCancellable          *worker_cancellable;
         char                  *session_id;
         guint32                is_stopping : 1;
 
@@ -1040,6 +1041,8 @@ register_worker (GdmDBusWorkerManager  *worker_manager_interface,
 
         g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (conversation->worker_proxy), G_MAXINT);
 
+        conversation->worker_cancellable = g_cancellable_new ();
+
         g_signal_connect (conversation->worker_proxy,
                           "username-changed",
                           G_CALLBACK (worker_on_username_changed), conversation);
@@ -1676,6 +1679,9 @@ free_conversation (GdmSessionConversation *conversation)
         g_free (conversation->session_id);
         g_clear_object (&conversation->worker_manager_interface);
 
+        g_cancellable_cancel (conversation->worker_cancellable);
+        g_clear_object (&conversation->worker_cancellable);
+
         if (conversation->worker_proxy != NULL) {
                 g_signal_handlers_disconnect_by_func (conversation->worker_proxy,
                                                       G_CALLBACK (worker_on_username_changed),
@@ -2111,7 +2117,7 @@ send_setup (GdmSession *self,
                                             display_hostname,
                                             self->priv->display_is_local,
                                             self->priv->display_is_initial,
-                                            NULL,
+                                            conversation->worker_cancellable,
                                             (GAsyncReadyCallback) on_setup_complete_cb,
                                             conversation);
         }
@@ -2177,7 +2183,7 @@ send_setup_for_user (GdmSession *self,
                                                      display_hostname,
                                                      self->priv->display_is_local,
                                                      self->priv->display_is_initial,
-                                                     NULL,
+                                                     conversation->worker_cancellable,
                                                      (GAsyncReadyCallback) on_setup_complete_cb,
                                                      conversation);
         }
@@ -2239,7 +2245,7 @@ send_setup_for_program (GdmSession *self,
                                                         self->priv->display_is_local,
                                                         self->priv->display_is_initial,
                                                         log_file,
-                                                        NULL,
+                                                        conversation->worker_cancellable,
                                                         (GAsyncReadyCallback) on_setup_complete_cb,
                                                         conversation);
         }
@@ -2297,7 +2303,7 @@ gdm_session_authenticate (GdmSession *self,
         conversation = find_conversation_by_name (self, service_name);
         if (conversation != NULL) {
                 gdm_dbus_worker_call_authenticate (conversation->worker_proxy,
-                                                   NULL,
+                                                   conversation->worker_cancellable,
                                                    (GAsyncReadyCallback) on_authenticate_cb,
                                                    conversation);
         }
@@ -2314,7 +2320,7 @@ gdm_session_authorize (GdmSession *self,
         conversation = find_conversation_by_name (self, service_name);
         if (conversation != NULL) {
                 gdm_dbus_worker_call_authorize (conversation->worker_proxy,
-                                                NULL,
+                                                conversation->worker_cancellable,
                                                 (GAsyncReadyCallback) on_authorize_cb,
                                                 conversation);
         }
@@ -2331,7 +2337,7 @@ gdm_session_accredit (GdmSession *self,
         conversation = find_conversation_by_name (self, service_name);
         if (conversation != NULL) {
                 gdm_dbus_worker_call_establish_credentials (conversation->worker_proxy,
-                                                            NULL,
+                                                            conversation->worker_cancellable,
                                                             (GAsyncReadyCallback) 
on_establish_credentials_cb,
                                                             conversation);
         }
@@ -2345,7 +2351,8 @@ send_environment_variable (const char             *key,
 {
         gdm_dbus_worker_call_set_environment_variable (conversation->worker_proxy,
                                                        key, value,
-                                                       NULL, NULL, NULL);
+                                                       conversation->worker_cancellable,
+                                                       NULL, NULL);
 }
 
 static void
@@ -2535,7 +2542,8 @@ send_display_mode (GdmSession *self,
         mode = gdm_session_get_display_mode (self);
         gdm_dbus_worker_call_set_session_display_mode (conversation->worker_proxy,
                                                        gdm_session_display_mode_to_string (mode),
-                                                       NULL, NULL, NULL);
+                                                       conversation->worker_cancellable,
+                                                       NULL, NULL);
 }
 
 static void
@@ -2551,7 +2559,8 @@ send_session_type (GdmSession *self,
         gdm_dbus_worker_call_set_environment_variable (conversation->worker_proxy,
                                                        "XDG_SESSION_TYPE",
                                                        session_type,
-                                                       NULL, NULL, NULL);
+                                                       conversation->worker_cancellable,
+                                                       NULL, NULL);
 }
 
 void
@@ -2569,7 +2578,7 @@ gdm_session_open_session (GdmSession *self,
                 send_session_type (self, conversation);
 
                 gdm_dbus_worker_call_open (conversation->worker_proxy,
-                                           NULL,
+                                           conversation->worker_cancellable,
                                            (GAsyncReadyCallback) on_opened, conversation);
         }
 }
@@ -2755,7 +2764,7 @@ gdm_session_start_session (GdmSession *self,
 
         gdm_dbus_worker_call_start_program (conversation->worker_proxy,
                                             program,
-                                            NULL,
+                                            conversation->worker_cancellable,
                                             (GAsyncReadyCallback) on_start_program_cb,
                                             conversation);
         g_free (program);
@@ -2887,7 +2896,7 @@ gdm_session_start_reauthentication (GdmSession *session,
         gdm_dbus_worker_call_start_reauthentication (conversation->worker_proxy,
                                                      (int) pid_of_caller,
                                                      (int) uid_of_caller,
-                                                     NULL,
+                                                     conversation->worker_cancellable,
                                                      (GAsyncReadyCallback) on_reauthentication_started_cb,
                                                      conversation);
 }
@@ -3124,7 +3133,8 @@ gdm_session_select_session (GdmSession *self,
 
                 gdm_dbus_worker_call_set_session_name (conversation->worker_proxy,
                                                        get_session_name (self),
-                                                       NULL, NULL, NULL);
+                                                       conversation->worker_cancellable,
+                                                       NULL, NULL);
         }
 }
 


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