[gtk+/wip/listbox] GtkListBox: Protect against reentrancy.



commit 697e4066b0580a504d6eb4d371b41583bd336e7b
Author: Alexander Larsson <alexl redhat com>
Date:   Wed Jun 12 13:20:15 2013 +0200

    GtkListBox: Protect against reentrancy.
    
    Activating a row may destroy the widget, so keep a ref since
    we're doing thing to the listbox after emission.

 gtk/gtklistbox.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c
index 6a77699..bd9a852 100644
--- a/gtk/gtklistbox.c
+++ b/gtk/gtklistbox.c
@@ -1233,24 +1233,30 @@ gtk_list_box_real_button_release_event (GtkWidget *widget,
   GtkListBox *list_box = GTK_LIST_BOX (widget);
   GtkListBoxPrivate *priv = list_box->priv;
 
+  /* Take a ref to protect against reentrancy (i.e. the activation may destroy the widget) */
+  g_object_ref (list_box);
+
   if (event->button == GDK_BUTTON_PRIMARY)
     {
       if (priv->active_row != NULL &&
           priv->active_row_active)
         {
+          gtk_widget_unset_state_flags (GTK_WIDGET (priv->active_row),
+                                        GTK_STATE_FLAG_ACTIVE);
+
           if (priv->activate_single_click)
             gtk_list_box_select_and_activate (list_box, priv->active_row);
           else
             gtk_list_box_update_selected (list_box, priv->active_row);
 
-          gtk_widget_unset_state_flags (GTK_WIDGET (priv->active_row),
-                                        GTK_STATE_FLAG_ACTIVE);
         }
       priv->active_row = NULL;
       priv->active_row_active = FALSE;
       gtk_widget_queue_draw (GTK_WIDGET (list_box));
   }
 
+  g_object_unref (list_box);
+
   return FALSE;
 }
 


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