[gdm] server: maintain active_servers list through explicit weak references



commit a9367393441b6e9026cb28778f81ec91f95f078d
Author: Ray Strode <rstrode redhat com>
Date:   Mon Mar 17 23:47:16 2014 -0400

    server: maintain active_servers list through explicit weak references
    
    It's possible for the server object to get freed before its
    child watch fires (if the slave is stopped early), so
    we can't rely on the child watch to main accounting on the active
    servers list.
    
    This commit changes the code over to use weak references instead.

 daemon/gdm-server.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/daemon/gdm-server.c b/daemon/gdm-server.c
index d4ee853..ccb26a3 100644
--- a/daemon/gdm-server.c
+++ b/daemon/gdm-server.c
@@ -703,14 +703,18 @@ server_child_watch (GPid       pid,
                 g_signal_emit (server, signals [DIED], 0, num);
         }
 
-        active_servers = g_slist_remove (active_servers, server);
-
         g_spawn_close_pid (server->priv->pid);
         server->priv->pid = -1;
 
         g_object_unref (server);
 }
 
+static void
+prune_active_servers_list (GdmServer *server)
+{
+        active_servers = g_slist_remove (active_servers, server);
+}
+
 static gboolean
 gdm_server_spawn (GdmServer    *server,
                   const char   *vtarg,
@@ -750,6 +754,11 @@ gdm_server_spawn (GdmServer    *server,
 
         active_servers = g_slist_append (active_servers, server);
 
+        g_object_weak_ref (G_OBJECT (server),
+                           (GWeakNotify)
+                           prune_active_servers_list,
+                           server);
+
         gdm_server_launch_sigusr1_thread_if_needed ();
 
         if (!g_spawn_async_with_pipes (NULL,


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