Merge branch '1318-dbus-server-race' into 'master'

gdbusserver: Keep a strong reference to the server in callbacks

Closes #1318

See merge request GNOME/glib!1193
This commit is contained in:
Simon McVittie 2019-10-29 08:28:56 +00:00
commit 714f9f92b7

View File

@ -179,6 +179,8 @@ g_dbus_server_finalize (GObject *object)
{
GDBusServer *server = G_DBUS_SERVER (object);
g_assert (!server->active);
if (server->authentication_observer != NULL)
g_object_unref (server->authentication_observer);
@ -197,19 +199,8 @@ g_dbus_server_finalize (GObject *object)
g_free (server->nonce);
}
if (server->unix_socket_path)
{
if (g_unlink (server->unix_socket_path) != 0)
g_warning ("Failed to delete %s: %s", server->unix_socket_path, g_strerror (errno));
g_free (server->unix_socket_path);
}
if (server->nonce_file)
{
if (g_unlink (server->nonce_file) != 0)
g_warning ("Failed to delete %s: %s", server->nonce_file, g_strerror (errno));
g_free (server->nonce_file);
}
g_free (server->unix_socket_path);
g_free (server->nonce_file);
g_main_context_unref (server->main_context_at_construction);
@ -622,6 +613,12 @@ g_dbus_server_start (GDBusServer *server)
return;
/* Right now we don't have any transport not using the listener... */
g_assert (server->is_using_listener);
server->run_signal_handler_id = g_signal_connect_data (G_SOCKET_SERVICE (server->listener),
"run",
G_CALLBACK (on_run),
g_object_ref (server),
(GClosureNotify) g_object_unref,
0 /* flags */);
g_socket_service_start (G_SOCKET_SERVICE (server->listener));
server->active = TRUE;
g_object_notify (G_OBJECT (server), "active");
@ -648,6 +645,18 @@ g_dbus_server_stop (GDBusServer *server)
g_socket_service_stop (G_SOCKET_SERVICE (server->listener));
server->active = FALSE;
g_object_notify (G_OBJECT (server), "active");
if (server->unix_socket_path)
{
if (g_unlink (server->unix_socket_path) != 0)
g_warning ("Failed to delete %s: %s", server->unix_socket_path, g_strerror (errno));
}
if (server->nonce_file)
{
if (g_unlink (server->nonce_file) != 0)
g_warning ("Failed to delete %s: %s", server->nonce_file, g_strerror (errno));
}
}
/* ---------------------------------------------------------------------------------------------------- */
@ -1159,15 +1168,7 @@ initable_init (GInitable *initable,
if (ret)
{
if (last_error != NULL)
g_error_free (last_error);
/* Right now we don't have any transport not using the listener... */
g_assert (server->is_using_listener);
server->run_signal_handler_id = g_signal_connect (G_SOCKET_SERVICE (server->listener),
"run",
G_CALLBACK (on_run),
server);
g_clear_error (&last_error);
}
else
{