From b3cf5cbd0bfcfe53f82a72d276683aebd15d3828 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Tue, 20 Jul 2010 12:14:30 -0400 Subject: [PATCH] GDBusServer: Avoid handling incoming connections after stop() has been called Without this fix, we'd sometimes run code after stop() and finalize() to handle incoming requests. This was observed in the gdbus-peer test case occasionally crashing: $ ./gdbus-peer /gdbus/peer-to-peer: OK /gdbus/delayed-message-processing: OK /gdbus/nonce-tcp: GLib-GObject-WARNING **: invalid uninstantiatable type `(null)' in cast to `GDBusServer' aborting... Signed-off-by: David Zeuthen --- gio/gdbusserver.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/gio/gdbusserver.c b/gio/gdbusserver.c index abd464e18..14f94a636 100644 --- a/gio/gdbusserver.c +++ b/gio/gdbusserver.c @@ -92,6 +92,7 @@ struct _GDBusServer GSocketListener *listener; gboolean is_using_listener; + gulong run_signal_handler_id; /* The result of g_main_context_get_thread_default() when the object * was created (the GObject _init() function) - this is used for delivery @@ -158,6 +159,9 @@ g_dbus_server_finalize (GObject *object) if (server->authentication_observer != NULL) g_object_unref (server->authentication_observer); + if (server->run_signal_handler_id > 0) + g_signal_handler_disconnect (server->listener, server->run_signal_handler_id); + if (server->listener != NULL) g_object_unref (server->listener); @@ -489,10 +493,10 @@ g_dbus_server_new_sync (const gchar *address, { /* Right now we don't have any transport not using the listener... */ g_assert (server->is_using_listener); - g_signal_connect (G_SOCKET_SERVICE (server->listener), - "run", - G_CALLBACK (on_run), - server); + server->run_signal_handler_id = g_signal_connect (G_SOCKET_SERVICE (server->listener), + "run", + G_CALLBACK (on_run), + server); } return server; @@ -605,6 +609,9 @@ g_dbus_server_stop (GDBusServer *server) return; /* Right now we don't have any transport not using the listener... */ g_assert (server->is_using_listener); + g_assert (server->run_signal_handler_id > 0); + g_signal_handler_disconnect (server->listener, server->run_signal_handler_id); + server->run_signal_handler_id = 0; g_socket_service_stop (G_SOCKET_SERVICE (server->listener)); server->active = FALSE; g_object_notify (G_OBJECT (server), "active");