actionmuxer: check for observer before unregistering
authorChristian Hergert <chergert@redhat.com>
Mon, 2 May 2022 22:33:34 +0000 (15:33 -0700)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 12 May 2022 01:54:33 +0000 (21:54 -0400)
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

index 60ee06dc58d5d7198d682d0d2f67533ba45d8891..94f734ca918e4ddfaa3755a951436a39341c7150 100644 (file)
@@ -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);
+        }
     }
 }