Merge branch 'fix-filechooser-crash' into 'main'

window: Fix crash when unexporting unrealized window

See merge request GNOME/gtk!7769
This commit is contained in:
Matthias Clasen
2024-10-03 15:53:44 +00:00
2 changed files with 24 additions and 3 deletions

View File

@@ -754,6 +754,7 @@ gtk_print_output_stream_set_print_done (GtkPrintOutputStream *stream,
typedef struct
{
GtkWindow *exported_window;
char *exported_window_handle;
char *portal_handle;
unsigned int response_signal_id;
unsigned int token;
@@ -778,6 +779,9 @@ print_task_data_free (gpointer data)
PrintTaskData *ptd = data;
g_free (ptd->portal_handle);
if (ptd->exported_window && ptd->exported_window_handle)
gtk_window_unexport_handle (ptd->exported_window, ptd->exported_window_handle);
g_clear_pointer (&ptd->exported_window_handle, g_free);
g_clear_object (&ptd->exported_window);
if (ptd->fds[0] != -1)
close (ptd->fds[0]);
@@ -872,8 +876,12 @@ cleanup_portal_call_data (GTask *task)
ptd->response_signal_id = 0;
}
if (ptd->exported_window && ptd->exported_window_handle)
gtk_window_unexport_handle (ptd->exported_window, ptd->exported_window_handle);
g_clear_pointer (&ptd->portal_handle, g_free);
g_clear_object (&ptd->exported_window);
g_clear_pointer (&ptd->exported_window_handle, g_free);
}
/* }}} */
@@ -1016,6 +1024,12 @@ setup_window_handle_exported (GtkWindow *window,
g_assert (ptd->portal_handle == NULL);
ptd->portal_handle = gtk_get_portal_request_path (connection, &handle_token);
if (window)
{
ptd->exported_window = g_object_ref (window);
ptd->exported_window_handle = g_strdup (window_handle);
}
g_assert (ptd->response_signal_id == 0);
ptd->response_signal_id =
g_dbus_connection_signal_subscribe (connection,
@@ -1213,7 +1227,10 @@ print_window_handle_exported (GtkWindow *window,
int idx;
if (window)
ptd->exported_window = g_object_ref (window);
{
ptd->exported_window = g_object_ref (window);
ptd->exported_window_handle = g_strdup (window_handle);
}
g_assert (ptd->fds[0] != -1);

View File

@@ -6342,7 +6342,7 @@ unprefix_handle (const char *handle)
if (g_str_has_prefix (handle, "wayland:"))
return handle + strlen ("wayland:");
else if (g_str_has_prefix (handle, "x11:"))
return handle + strlen ("x1!:");
return handle + strlen ("x11:");
else
return handle;
}
@@ -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 *