From 547b2891cb2f35ef87528e022446a7be1a619d2f Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Mon, 2 May 2022 14:55:55 -0700 Subject: [PATCH 1/2] actionmuxer: set handler ids initially to zero These were getting created with possible non-zero values and then inserted into a hashtable where the readers may not know the state of the group. Ensure those values are set to zero until we assign them below. --- gtk/gtkactionmuxer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gtk/gtkactionmuxer.c b/gtk/gtkactionmuxer.c index 06660ddf89..60ee06dc58 100644 --- a/gtk/gtkactionmuxer.c +++ b/gtk/gtkactionmuxer.c @@ -1269,7 +1269,7 @@ gtk_action_muxer_insert (GtkActionMuxer *muxer, if (!muxer->groups) muxer->groups = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, gtk_action_muxer_free_group); - group = g_slice_new (Group); + group = g_slice_new0 (Group); group->muxer = muxer; group->group = g_object_ref (action_group); group->prefix = g_strdup (prefix); From 0382e3b46c1e68b8daf61baa3873fc1d50c56192 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Mon, 2 May 2022 15:33:34 -0700 Subject: [PATCH 2/2] 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 60ee06dc58..94f734ca91 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); + } } }