[gtk/wip/chergert/action-parent: 3/4] actionmuxer: check for observer before unregistering




commit 3e76026ab462c219334d96a70076b7fdc3a7a9a2
Author: Christian Hergert <chergert redhat com>
Date:   Mon May 2 15:33:34 2022 -0700

    actionmuxer: check for observer before unregistering
    
    This can happen if the group can be resolved even when doing the initial
    registration of an action as observer will not yet be in the GSList of
    watchers (and therefore has no weak references).
    
    Fixes a warning like the following:
    
     g_object_weak_unref: couldn't find weak ref

 gtk/gtkactionmuxer.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkactionmuxer.c b/gtk/gtkactionmuxer.c
index 6cbf7421da..46414e228e 100644
--- a/gtk/gtkactionmuxer.c
+++ b/gtk/gtkactionmuxer.c
@@ -991,13 +991,15 @@ gtk_action_muxer_unregister_observer (GtkActionObservable *observable,
                                       GtkActionObserver   *observer)
 {
   GtkActionMuxer *muxer = GTK_ACTION_MUXER (observable);
-  Action *action;
+  Action *action = find_observers (muxer, name);
 
-  action = find_observers (muxer, name);
   if (action)
     {
-      g_object_weak_unref (G_OBJECT (observer), gtk_action_muxer_weak_notify, action);
-      gtk_action_muxer_unregister_internal (action, observer);
+      if (g_slist_find (action->watchers, observer) != NULL)
+        {
+          g_object_weak_unref (G_OBJECT (observer), gtk_action_muxer_weak_notify, action);
+          gtk_action_muxer_unregister_internal (action, observer);
+        }
     }
 }
 


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