Blame SOURCES/window-Streamline-RestoreTabData-memory-management.patch

6b1755
From 4bdd3fad8d51e50e3539c8e04bc91538467bd236 Mon Sep 17 00:00:00 2001
6b1755
From: =?UTF-8?q?Ant=C3=B3nio=20Fernandes?= <antoniof@gnome.org>
6b1755
Date: Wed, 8 Jul 2020 14:44:38 +0100
6b1755
Subject: [PATCH] window: Streamline RestoreTabData memory management
6b1755
6b1755
When restoring the back and forward lists, we make a deep copy only to
6b1755
free the data immediately afterwards.
6b1755
6b1755
Instead of reallocating the lists unnecessarily, let's just steal them.
6b1755
6b1755
Also, use g_queue_free_full() to make free_restore_tab_data() a proper
6b1755
GDestroyNotify; also define it in window-slot.c, where it belongs.
6b1755
---
6b1755
 src/nautilus-window-slot.c | 16 ++++++++++++++--
6b1755
 src/nautilus-window-slot.h |  1 +
6b1755
 src/nautilus-window.c      | 20 ++------------------
6b1755
 3 files changed, 17 insertions(+), 20 deletions(-)
6b1755
6b1755
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
6b1755
index c3260aeb0..bf040bff2 100644
6b1755
--- a/src/nautilus-window-slot.c
6b1755
+++ b/src/nautilus-window-slot.c
6b1755
@@ -155,6 +155,18 @@ static void trash_state_changed_cb (NautilusTrashMonitor *monitor,
6b1755
                                     gboolean              is_empty,
6b1755
                                     gpointer              user_data);
6b1755
 
6b1755
+void
6b1755
+free_restore_tab_data (gpointer data)
6b1755
+{
6b1755
+    RestoreTabData *tab_data = data;
6b1755
+
6b1755
+    g_list_free_full (tab_data->back_list, g_object_unref);
6b1755
+    g_list_free_full (tab_data->forward_list, g_object_unref);
6b1755
+    nautilus_file_unref (tab_data->file);
6b1755
+
6b1755
+    g_free (tab_data);
6b1755
+}
6b1755
+
6b1755
 void
6b1755
 nautilus_window_slot_restore_from_data (NautilusWindowSlot *self,
6b1755
                                         RestoreTabData     *data)
6b1755
@@ -163,9 +175,9 @@ nautilus_window_slot_restore_from_data (NautilusWindowSlot *self,
6b1755
 
6b1755
     priv = nautilus_window_slot_get_instance_private (self);
6b1755
 
6b1755
-    priv->back_list = g_list_copy_deep (data->back_list, (GCopyFunc) g_object_ref, NULL);
6b1755
+    priv->back_list = g_steal_pointer (&data->back_list);
6b1755
 
6b1755
-    priv->forward_list = g_list_copy_deep (data->forward_list, (GCopyFunc) g_object_ref, NULL);
6b1755
+    priv->forward_list = g_steal_pointer (&data->forward_list);
6b1755
 
6b1755
     priv->view_mode_before_search = data->view_before_search;
6b1755
 
6b1755
diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h
6b1755
index 573357d9b..bda1a920f 100644
6b1755
--- a/src/nautilus-window-slot.h
6b1755
+++ b/src/nautilus-window-slot.h
6b1755
@@ -125,4 +125,5 @@ RestoreTabData* nautilus_window_slot_get_restore_tab_data (NautilusWindowSlot *s
6b1755
 /* Only used by slot-dnd */
6b1755
 NautilusView*  nautilus_window_slot_get_current_view       (NautilusWindowSlot *slot);
6b1755
 
6b1755
+void free_restore_tab_data                                 (gpointer data);
6b1755
 #endif /* NAUTILUS_WINDOW_SLOT_H */
6b1755
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
6b1755
index 1f8d5208e..175da6fce 100644
6b1755
--- a/src/nautilus-window.c
6b1755
+++ b/src/nautilus-window.c
6b1755
@@ -79,8 +79,6 @@ static GtkWidget *nautilus_window_ensure_location_entry (NautilusWindow *window)
6b1755
 static void close_slot (NautilusWindow     *window,
6b1755
                         NautilusWindowSlot *slot,
6b1755
                         gboolean            remove_from_notebook);
6b1755
-static void free_restore_tab_data (gpointer data,
6b1755
-                                   gpointer user_data);
6b1755
 
6b1755
 /* Sanity check: highest mouse button value I could find was 14. 5 is our
6b1755
  * lower threshold (well-documented to be the one of the button events for the
6b1755
@@ -1374,7 +1372,7 @@ action_restore_tab (GSimpleAction *action,
6b1755
     nautilus_window_slot_open_location_full (slot, location, flags, NULL);
6b1755
     nautilus_window_slot_restore_from_data (slot, data);
6b1755
 
6b1755
-    free_restore_tab_data (data, NULL);
6b1755
+    free_restore_tab_data (data);
6b1755
 }
6b1755
 
6b1755
 static void
6b1755
@@ -2501,19 +2499,6 @@ nautilus_window_destroy (GtkWidget *object)
6b1755
     GTK_WIDGET_CLASS (nautilus_window_parent_class)->destroy (object);
6b1755
 }
6b1755
 
6b1755
-static void
6b1755
-free_restore_tab_data (gpointer data,
6b1755
-                       gpointer user_data)
6b1755
-{
6b1755
-    RestoreTabData *tab_data = data;
6b1755
-
6b1755
-    g_list_free_full (tab_data->back_list, g_object_unref);
6b1755
-    g_list_free_full (tab_data->forward_list, g_object_unref);
6b1755
-    nautilus_file_unref (tab_data->file);
6b1755
-
6b1755
-    g_free (tab_data);
6b1755
-}
6b1755
-
6b1755
 static void
6b1755
 nautilus_window_finalize (GObject *object)
6b1755
 {
6b1755
@@ -2548,8 +2533,7 @@ nautilus_window_finalize (GObject *object)
6b1755
                                           G_CALLBACK (nautilus_window_on_undo_changed),
6b1755
                                           window);
6b1755
 
6b1755
-    g_queue_foreach (priv->tab_data_queue, (GFunc) free_restore_tab_data, NULL);
6b1755
-    g_queue_free (priv->tab_data_queue);
6b1755
+    g_queue_free_full (priv->tab_data_queue, free_restore_tab_data);
6b1755
 
6b1755
     g_object_unref (priv->pad_controller);
6b1755
 
6b1755
-- 
6b1755
2.35.1
6b1755