[libsecret/wip/dueno/gtask-dup-error] secret-item: properly chain-up GTasks around GDBusProxy::init_async




commit 8965b10d779a0d02a0484a4260f21fe749ccba81
Author: Daiki Ueno <dueno src gnome org>
Date:   Sun May 8 09:32:23 2022 +0200

    secret-item: properly chain-up GTasks around GDBusProxy::init_async
    
    SecretItem::init_async internally calls GDBusProxy::init_async and
    performs some additional error processing afterwards.  Previously a
    single GTask was passed around, and that caused an issue in
    the (additional) error path, as GDBusProxy::init_async may have
    already called g_task_return_boolean(task, TRUE):
    
      g_task_return_error: assertion '!task->ever_returned' failed
    
    This fixes the issue by creating a temporary GTask around
    GDBusProxy::init_async call.
    
    Signed-off-by: Daiki Ueno <dueno src gnome org>

 libsecret/secret-item.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/libsecret/secret-item.c b/libsecret/secret-item.c
index 6773c4b..0422e36 100644
--- a/libsecret/secret-item.c
+++ b/libsecret/secret-item.c
@@ -512,17 +512,29 @@ on_init_service (GObject *source,
        g_clear_object (&task);
 }
 
+typedef struct {
+       GAsyncReadyCallback callback;
+       gpointer user_data;
+} InitClosure;
+
 static void
 on_init_base (GObject *source,
               GAsyncResult *result,
               gpointer user_data)
 {
-       GTask *task = G_TASK (user_data);
-       GCancellable *cancellable = g_task_get_cancellable (task);
+       GTask *base_task = G_TASK (user_data);
+       InitClosure *init = g_task_get_task_data (base_task);
+       gpointer source_tag = g_task_get_source_tag (base_task);
+       GCancellable *cancellable = g_task_get_cancellable (base_task);
+       GTask *task;
        SecretItem *self = SECRET_ITEM (source);
        GDBusProxy *proxy = G_DBUS_PROXY (self);
        GError *error = NULL;
 
+       task = g_task_new (source, cancellable, init->callback, init->user_data);
+       g_task_set_source_tag (task, source_tag);
+       g_clear_object (&base_task);
+
        if (!secret_item_async_initable_parent_iface->init_finish (G_ASYNC_INITABLE (self),
                                                                   result, &error)) {
                g_task_return_error (task, g_steal_pointer (&error));
@@ -535,7 +547,7 @@ on_init_base (GObject *source,
 
        } else if (self->pv->service == NULL) {
                secret_service_get (SECRET_SERVICE_NONE, cancellable,
-                                   on_init_service, g_steal_pointer (&task));
+                                   on_init_service, g_steal_pointer (&task));
 
        } else {
                item_ensure_for_flags_async (self, self->pv->init_flags, task);
@@ -552,10 +564,16 @@ secret_item_async_initable_init_async (GAsyncInitable *initable,
                                        gpointer user_data)
 {
        GTask *task;
+       InitClosure *init;
 
-       task = g_task_new (initable, cancellable, callback, user_data);
+       task = g_task_new (initable, cancellable, NULL, NULL);
        g_task_set_source_tag (task, secret_item_async_initable_init_async);
 
+       init = g_new0 (InitClosure, 1);
+       init->callback = callback;
+       init->user_data = user_data;
+       g_task_set_task_data (task, init, g_free);
+
        secret_item_async_initable_parent_iface->init_async (initable, io_priority,
                                                             cancellable,
                                                             on_init_base,


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