[gtk+/gtk-2-24] ComboBox: Use iter before popdown() may invalidate



commit 47bea2deaae3be3501beb5b4edc556b70dc67e39
Author: Daniel Boles <dboles src gnome org>
Date:   Fri Aug 25 21:00:51 2017 +0100

    ComboBox: Use iter before popdown() may invalidate
    
    Bad actors, such as our very own FileChooserButton, may connect to the
    :popped-up property and alter the model as the menu becomes in/visible.
    
    We were getting an iter to the model while popped-up, then doing
    popdown(), then using the iter, which may have just been invalidated by
    the errant notify::popped-up handler. If so, we quickly crash fatally.
    
    This is clearly bonkers, but until such patterns are removed, we have to
    work around them. So, set_active() from the clicked item while it is
    known to be valid, by moving the call to set_active() before popdown().
    
    While here, change set_active_iter(iter) to set_active_internal(path) to
    avoid pointlessly going through the iter to get the path we already have
    
    https://bugzilla.gnome.org/show_bug.cgi?id=729651

 gtk/gtkcombobox.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c
index 6271349..0fd5911 100644
--- a/gtk/gtkcombobox.c
+++ b/gtk/gtkcombobox.c
@@ -4153,13 +4153,17 @@ gtk_combo_box_list_button_released (GtkWidget      *widget,
     return TRUE; /* clicked outside window? */
 
   gtk_tree_model_get_iter (priv->model, &iter, path);
+
+  /* Use iter before popdown, as mis-users like GtkFileChooserButton alter the
+   * model during notify::popped-up, which means the iterator becomes invalid.
+   */
+  if (tree_column_row_is_sensitive (combo_box, &iter))
+    gtk_combo_box_set_active_internal (combo_box, path);
+
   gtk_tree_path_free (path);
 
   gtk_combo_box_popdown (combo_box);
 
-  if (tree_column_row_is_sensitive (combo_box, &iter))
-    gtk_combo_box_set_active_iter (combo_box, &iter);
-
   return TRUE;
 }
 


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