gdbusserver: Keep a strong reference to the server in callbacks

The `on_run()` function could be executed in any worker thread from the
`GThreadedSocketListener`, but didn’t previously hold a strong reference
to the `GDBusServer`, which meant the server could be finalised in
another thread while `on_run()` was still running.

This was not ideal.

Hold a strong reference to the `GDBusServer` while the socket listener
is listening, i.e. between every paired call to `g_dbus_server_start()`
and `g_dbus_server_stop()`.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1318
This commit is contained in:
Philip Withnall 2019-10-28 20:44:07 +00:00
parent 8e32b8e87f
commit 0c07e672a2

View File

@ -613,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");
@ -1162,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
{