From 2a10ec7c444516d8b1b35863f9b36a5f88fe7464 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 12 Sep 2024 09:40:45 +1200 Subject: [PATCH] Fix crash quitting application due to iterating over a changing list. (flutter/engine#55062) Detected as the FlPlatformHandlerTest.ExitApplicationDispose was crashing sometimes, valgrind showed invalid memory access. --- .../src/flutter/shell/platform/linux/fl_platform_handler.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/shell/platform/linux/fl_platform_handler.cc b/engine/src/flutter/shell/platform/linux/fl_platform_handler.cc index 9eb004ca00..28db474174 100644 --- a/engine/src/flutter/shell/platform/linux/fl_platform_handler.cc +++ b/engine/src/flutter/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);