From 221b18891e0d8be4a749afafe3444c9b4ed33e3e Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Tue, 10 Sep 2024 16:21:33 +1200 Subject: [PATCH] Fix crash quitting application due to iterating over a changing list. Detected as the FlPlatformHandlerTest.ExitApplicationDispose was crashing sometimes, valgrind showed invalid memory access. and valgrind showed --- shell/platform/linux/fl_platform_handler.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shell/platform/linux/fl_platform_handler.cc b/shell/platform/linux/fl_platform_handler.cc index 9eb004ca00c17..28db474174956 100644 --- a/shell/platform/linux/fl_platform_handler.cc +++ b/shell/platform/linux/fl_platform_handler.cc @@ -192,7 +192,10 @@ static void quit_application() { // Break them so the application object can cleanup. // See https://gitlab.gnome.org/GNOME/gtk/-/issues/6190 if (GTK_IS_APPLICATION(app)) { - GList* windows = gtk_application_get_windows(GTK_APPLICATION(app)); + // List is copied as it will be modified as windows are disconnected from + // the application. + g_autoptr(GList) windows = + g_list_copy(gtk_application_get_windows(GTK_APPLICATION(app))); for (GList* link = windows; link != NULL; link = link->next) { GtkWidget* window = GTK_WIDGET(link->data); gtk_window_set_application(GTK_WINDOW(window), NULL);