Blob Blame History Raw
From 45413c18167cddaefefc092b63ec75d8fadc6f50 Mon Sep 17 00:00:00 2001
From: Carlos Soriano <csoriano@gnome.org>
Date: Tue, 6 Oct 2015 16:56:59 +0200
Subject: [PATCH] application-actions: use valid window list

We were using the internal list of the application to
iterate through the windows and closing them.
Problem is that when closing one window, the list is modified,
so next time accessing the list we are accessing the "old"
list, which is invalid and makes nautilus crash.

To fix it make a copy of the list to preserve the consistency.

https://bugzilla.gnome.org/show_bug.cgi?id=755803
---
 src/nautilus-application-actions.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/nautilus-application-actions.c b/src/nautilus-application-actions.c
index e346d61..4246786 100644
--- a/src/nautilus-application-actions.c
+++ b/src/nautilus-application-actions.c
@@ -180,12 +180,19 @@ action_quit (GSimpleAction *action,
 {
 	GtkApplication *application = user_data;
 	GList *l;
+        GList *windows;
 
 	/* nautilus_window_close() doesn't do anything for desktop windows */
-	for (l = gtk_application_get_windows (GTK_APPLICATION (application)); l; l = l->next) {
+        windows = gtk_application_get_windows (GTK_APPLICATION (application));
+        /* make a copy, since the original list will be modified when destroying
+         * a window, making this list invalid */
+        windows = g_list_copy (windows);
+	for (l = windows; l != NULL; l = l->next) {
 		if (NAUTILUS_IS_WINDOW (l->data))
 			nautilus_window_close (NAUTILUS_WINDOW (l->data));
 	}
+
+        g_list_free (windows);
 }
 
 static void
-- 
2.5.0