From 2103ab99a5f654e10cecdbe26767e97ec9910e36 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Mon, 30 Sep 2024 18:51:14 +0300 Subject: [PATCH] window: Fix crash when unexporting unrealized window It is possible that the window gets unrealized while a handle to its surface is exported. This, naturally, invalidates the handle, so there is nothing left to unexport. We should just note that and do nothing, rather than crashing. Fixes a crash when a portal-backed file dialog parented to a window is closed after the window it was parented to. Reported-by: Ivan Molodetskikh Signed-off-by: Sergey Bugaev --- gtk/gtkwindow.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 604fe89050..eadba52296 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -6381,6 +6381,9 @@ gtk_window_export_handle (GtkWindow *window, GtkWindowPrivate *priv = gtk_window_get_instance_private (window); ExportHandleData *data; + if (G_UNLIKELY (!priv->surface)) + return FALSE; + data = g_new (ExportHandleData, 1); data->window = window; data->callback = callback; @@ -6397,7 +6400,8 @@ gtk_window_unexport_handle (GtkWindow *window, { GtkWindowPrivate *priv = gtk_window_get_instance_private (window); - gdk_toplevel_unexport_handle (GDK_TOPLEVEL (priv->surface), unprefix_handle (handle)); + if (G_LIKELY (priv->surface)) + gdk_toplevel_unexport_handle (GDK_TOPLEVEL (priv->surface), unprefix_handle (handle)); } static GtkPointerFocus *