From bcf04c4b6ae1543fd3f0d11b8c0f7907c1a0e14a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 1 Jun 2018 17:16:35 +0200 Subject: [PATCH 06/15] libgdm: Don't double-ref the connection got from task Both if we re-use the shared connection in `gdm_client_get_connection` and if we create a new one in `on_connected`, we steal the pointer here by using `g_task_propagate_pointer` and thus we don't have to add an additional reference to this connection when returning, or it won't ever be consumed by function customers. --- libgdm/gdm-client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libgdm/gdm-client.c b/libgdm/gdm-client.c index fa4ba8426..36292148c 100644 --- a/libgdm/gdm-client.c +++ b/libgdm/gdm-client.c @@ -509,76 +509,76 @@ on_got_manager_for_opening_connection (GdmClient *client, GAsyncResult *result, GTask *task) { GCancellable *cancellable; GdmManager *manager; GError *error; error = NULL; manager = g_task_propagate_pointer (G_TASK (result), &error); if (manager == NULL) { g_task_return_error (task, error); g_object_unref (task); return; } cancellable = g_task_get_cancellable (task); gdm_manager_call_open_session (manager, cancellable, (GAsyncReadyCallback) on_session_opened, task); g_object_unref (manager); } static GDBusConnection * gdm_client_get_connection_finish (GdmClient *client, GAsyncResult *result, GError **error) { - GDBusConnection *connection = NULL; + GDBusConnection *connection; g_return_val_if_fail (GDM_IS_CLIENT (client), FALSE); connection = g_task_propagate_pointer (G_TASK (result), error); if (connection == NULL) { return NULL; } if (client->priv->connection == NULL) { client->priv->connection = connection; g_object_add_weak_pointer (G_OBJECT (client->priv->connection), (gpointer *) &client->priv->connection); } - return g_object_ref (connection); + return connection; } static void gdm_client_get_connection (GdmClient *client, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GTask *task; g_return_if_fail (GDM_IS_CLIENT (client)); task = g_task_new (G_OBJECT (client), cancellable, callback, user_data); if (client->priv->connection != NULL) { g_task_return_pointer (task, g_object_ref (client->priv->connection), (GDestroyNotify) g_object_unref); g_object_unref (task); return; } get_manager (client, cancellable, (GAsyncReadyCallback) on_got_manager_for_opening_connection, task); -- 2.25.1