[gtk+] Ref the popover before activating the item



commit 907dae414a733f0beccb121d751365fd9128dd8e
Author: Garrett Regier <garrettregier gmail com>
Date:   Sat Aug 23 06:55:07 2014 -0700

    Ref the popover before activating the item
    
    Otherwise the item could cause the popover to be destroyed,
    for example a Quit item, and cause a warning to be printed.

 gtk/gtkmenusectionbox.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkmenusectionbox.c b/gtk/gtkmenusectionbox.c
index 1bc2472..648e933 100644
--- a/gtk/gtkmenusectionbox.c
+++ b/gtk/gtkmenusectionbox.c
@@ -145,11 +145,24 @@ gtk_popover_item_activate (GtkWidget *button,
                            gpointer   user_data)
 {
   GtkMenuTrackerItem *item = user_data;
+  GtkWidget *popover = NULL;
+
+  if (gtk_menu_tracker_item_get_role (item) == GTK_MENU_TRACKER_ITEM_ROLE_NORMAL)
+    {
+      /* Activating the item could cause the popover
+       * to be free'd, for example if it is a Quit item
+       */
+      popover = g_object_ref (gtk_widget_get_ancestor (button,
+                                                       GTK_TYPE_POPOVER));
+    }
 
   gtk_menu_tracker_item_activated (item);
 
-  if (gtk_menu_tracker_item_get_role (item) == GTK_MENU_TRACKER_ITEM_ROLE_NORMAL)
-    gtk_widget_hide (gtk_widget_get_ancestor (button, GTK_TYPE_POPOVER));
+  if (popover != NULL)
+    {
+      gtk_widget_hide (popover);
+      g_object_unref (popover);
+    }
 }
 
 static void


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