[gtk/wip/chergert/fix-use-after-free-switcher] stackswitcher: clear timer when widget id disposed




commit c2ca246aee0f9ebe01a26c18f116216621af0e26
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jun 2 10:19:42 2021 -0700

    stackswitcher: clear timer when widget id disposed
    
    If the widget is disposed while the cursor has a drag timeout queued, it
    can activate after finalization.

 gtk/gtkstackswitcher.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkstackswitcher.c b/gtk/gtkstackswitcher.c
index 502f3f3037..ffbfff98c2 100644
--- a/gtk/gtkstackswitcher.c
+++ b/gtk/gtkstackswitcher.c
@@ -225,6 +225,13 @@ gtk_stack_switcher_switch_timeout (gpointer data)
   return G_SOURCE_REMOVE;
 }
 
+static void
+clear_timer (gpointer data)
+{
+  if (data)
+    g_source_remove (GPOINTER_TO_UINT (data));
+}
+
 static void
 gtk_stack_switcher_drag_enter (GtkDropControllerMotion *motion,
                                double                   x,
@@ -239,7 +246,7 @@ gtk_stack_switcher_drag_enter (GtkDropControllerMotion *motion,
                                           gtk_stack_switcher_switch_timeout,
                                           button);
       g_source_set_name_by_id (switch_timer, "[gtk] gtk_stack_switcher_switch_timeout");
-      g_object_set_data (G_OBJECT (button), "-gtk-switch-timer", GUINT_TO_POINTER (switch_timer));
+      g_object_set_data_full (G_OBJECT (button), "-gtk-switch-timer", GUINT_TO_POINTER (switch_timer), 
clear_timer);
     }
 }
 


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