From bcad03da6c36ca8fe8161b756d1b05ad506e84ae Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 18 Oct 2022 14:21:51 -0400 Subject: [PATCH] window: Keep a reference to move_focus_widget If we don't take a reference, it can happen that the pointer is no longer valid by the time we dereference it in after_paint. --- gtk/gtkwindow.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 1de17f9048..6b4e2d77a7 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -2006,7 +2006,10 @@ gtk_window_root_set_focus (GtkRoot *root, { if (priv->move_focus && focus && gtk_widget_is_visible (focus)) - priv->move_focus = FALSE; + { + priv->move_focus = FALSE; + g_clear_object (&priv->move_focus_widget); + } return; } @@ -2028,7 +2031,10 @@ gtk_window_root_set_focus (GtkRoot *root, if (priv->move_focus && focus && gtk_widget_is_visible (focus)) - priv->move_focus = FALSE; + { + priv->move_focus = FALSE; + g_clear_object (&priv->move_focus_widget); + } g_object_notify (G_OBJECT (self), "focus-widget"); } @@ -2552,6 +2558,7 @@ gtk_window_dispose (GObject *object) g_list_free_full (priv->foci, (GDestroyNotify) gtk_pointer_focus_unref); priv->foci = NULL; + g_clear_object (&priv->move_focus_widget); gtk_window_set_focus (window, NULL); gtk_window_set_default_widget (window, NULL); @@ -4695,6 +4702,9 @@ maybe_unset_focus_and_default (GtkWindow *window) parent = _gtk_widget_get_parent (parent); } + + priv->move_focus = FALSE; + g_clear_object (&priv->move_focus_widget); } if (priv->unset_default) @@ -5155,7 +5165,7 @@ _gtk_window_unset_focus_and_default (GtkWindow *window, child = priv->focus_widget; if (child && (child == widget || gtk_widget_is_ancestor (child, widget))) { - priv->move_focus_widget = widget; + priv->move_focus_widget = g_object_ref (widget); priv->move_focus = TRUE; } -- 2.30.2