widget: Avoid a crash in event handling
authorMatthias Clasen <mclasen@redhat.com>
Wed, 25 Dec 2019 01:06:57 +0000 (20:06 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 25 Dec 2019 14:47:22 +0000 (09:47 -0500)
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

index dadee32823620155333fb91e85134ef21883c266..1c03acb20fa09c98f6381075a69577ccf4acbc3d 100644 (file)
@@ -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;