[gnome-software/554-keeps-rpm-ostreed-alive-forever: 16/19] rpm-ostree: Transaction cancellable can be NULL




commit 40a2fcf948f95ad30b8dc35fe4a601f563f4fb69
Author: Milan Crha <mcrha redhat com>
Date:   Wed Apr 7 18:20:36 2021 +0200

    rpm-ostree: Transaction cancellable can be NULL
    
    It can be NULL and it might not be disconnected properly every time.

 plugins/rpm-ostree/gs-plugin-rpm-ostree.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
---
diff --git a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
index fac0f3f91..78933e012 100644
--- a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
+++ b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
@@ -353,7 +353,7 @@ gs_rpmostree_transaction_get_response_sync (GsRPMOSTreeSysroot *sysroot_proxy,
 {
        GsRPMOSTreeTransaction *transaction = NULL;
        g_autoptr(GDBusConnection) peer_connection = NULL;
-       gint cancel_handler;
+       gint cancel_handler = 0;
        gulong signal_handler = 0;
        gulong notify_handler = 0;
        gboolean success = FALSE;
@@ -378,10 +378,12 @@ gs_rpmostree_transaction_get_response_sync (GsRPMOSTreeSysroot *sysroot_proxy,
        if (transaction == NULL)
                goto out;
 
-       /* setup cancel handler */
-       cancel_handler = g_cancellable_connect (cancellable,
-                                               G_CALLBACK (cancelled_handler),
-                                               transaction, NULL);
+       if (cancellable) {
+               /* setup cancel handler */
+               cancel_handler = g_cancellable_connect (cancellable,
+                                                       G_CALLBACK (cancelled_handler),
+                                                       transaction, NULL);
+       }
 
        signal_handler = g_signal_connect (transaction, "g-signal",
                                           G_CALLBACK (on_transaction_progress),
@@ -406,8 +408,6 @@ gs_rpmostree_transaction_get_response_sync (GsRPMOSTreeSysroot *sysroot_proxy,
                g_main_context_iteration (tp->context, TRUE);
        }
 
-       g_cancellable_disconnect (cancellable, cancel_handler);
-
        if (!g_cancellable_set_error_if_cancelled (cancellable, error)) {
                if (tp->error) {
                        g_propagate_error (error, g_steal_pointer (&tp->error));
@@ -420,6 +420,8 @@ gs_rpmostree_transaction_get_response_sync (GsRPMOSTreeSysroot *sysroot_proxy,
        }
 
 out:
+       if (cancel_handler)
+               g_cancellable_disconnect (cancellable, cancel_handler);
        if (notify_handler != 0)
                g_signal_handler_disconnect (transaction, notify_handler);
        if (signal_handler)


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