[gtk/kill-tree-menu: 3/51] popovermenu: Use a weak ref for active item
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/kill-tree-menu: 3/51] popovermenu: Use a weak ref for active item
- Date: Sun, 29 Dec 2019 22:13:42 +0000 (UTC)
commit 0b6e521dc5a6c2fe12158cc1e8a55dd3a974f3fc
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Dec 27 01:31:25 2019 -0500
popovermenu: Use a weak ref for active item
Otherwise, we can end up with a dangling pointer,
leading to badness.
gtk/gtkpopovermenu.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkpopovermenu.c b/gtk/gtkpopovermenu.c
index 447d21171a..dc3212b533 100644
--- a/gtk/gtkpopovermenu.c
+++ b/gtk/gtkpopovermenu.c
@@ -184,7 +184,10 @@ gtk_popover_menu_set_active_item (GtkPopoverMenu *menu,
if (menu->active_item != item)
{
if (menu->active_item)
- gtk_widget_unset_state_flags (menu->active_item, GTK_STATE_FLAG_SELECTED);
+ {
+ gtk_widget_unset_state_flags (menu->active_item, GTK_STATE_FLAG_SELECTED);
+ g_object_remove_weak_pointer (G_OBJECT (menu->active_item), (gpointer *)&menu->active_item);
+ }
menu->active_item = item;
@@ -192,6 +195,8 @@ gtk_popover_menu_set_active_item (GtkPopoverMenu *menu,
{
GtkWidget *popover;
+ g_object_add_weak_pointer (G_OBJECT (menu->active_item), (gpointer *)&menu->active_item);
+
gtk_widget_set_state_flags (menu->active_item, GTK_STATE_FLAG_SELECTED, FALSE);
if (GTK_IS_MODEL_BUTTON (item))
g_object_get (item, "popover", &popover, NULL);
@@ -277,6 +282,12 @@ gtk_popover_menu_dispose (GObject *object)
{
GtkPopoverMenu *popover = GTK_POPOVER_MENU (object);
+ if (popover->active_item)
+ {
+ g_object_remove_weak_pointer (G_OBJECT (popover->active_item), (gpointer *)&popover->active_item);
+ popover->active_item = NULL;
+ }
+
g_clear_object (&popover->model);
G_OBJECT_CLASS (gtk_popover_menu_parent_class)->dispose (object);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]