[gtk/matthiasc/for-master] widget: Avoid a crash in event handling



commit 453dfe180993c737a63bce798a5efa7056a4eda1
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Dec 24 20:06:57 2019 -0500

    widget: Avoid a crash in event handling
    
    I was seeing crashes in gtk_widget_run_controllers.
    We were accessing the controller after calling out
    to application code that might remove it. Better
    be safe and do the access before.

 gtk/gtkwidget.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index dadee32823..1c03acb20f 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -5207,14 +5207,22 @@ gtk_widget_run_controllers (GtkWidget           *widget,
           controller_phase = gtk_event_controller_get_propagation_phase (controller);
 
           if (controller_phase == phase)
-            handled |= gtk_event_controller_handle_event (controller, event);
+            {
+              gboolean this_handled;
+              gboolean is_gesture;
 
-          /* Non-gesture controllers are basically unique entities not meant
-           * to collaborate with anything else. Break early if any such event
-           * controller handled the event.
-           */
-          if (handled && !GTK_IS_GESTURE (controller))
-            break;
+              is_gesture = GTK_IS_GESTURE (controller);
+              this_handled = gtk_event_controller_handle_event (controller, event);
+
+              handled |= this_handled;
+
+              /* Non-gesture controllers are basically unique entities not meant
+               * to collaborate with anything else. Break early if any such event
+               * controller handled the event.
+               */
+              if (this_handled && !is_gesture)
+                break;
+            }
         }
 
       l = next;


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