From 9784a263a78f1ea67abc279d7159e6b96816978a Mon Sep 17 00:00:00 2001
From: Alexander Schwinn <alexxcons@xfce.org>
Date: Thu, 29 Feb 2024 18:35:01 +0100
Subject: [PATCH] Fix mem leak in action-manager (#573)

---
 thunar/thunar-action-manager.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/thunar/thunar-action-manager.c b/thunar/thunar-action-manager.c
index df4f21369..997aa9164 100644
--- a/thunar/thunar-action-manager.c
+++ b/thunar/thunar-action-manager.c
@@ -2784,6 +2784,7 @@ thunar_action_manager_create_document_submenu_templates (ThunarActionManager *ac
   GtkWidget         *submenu;
   GtkWidget         *image;
   GtkWidget         *item;
+  GList             *files_sorted;
   GList             *lp;
   GList             *dirs = NULL;
   GList             *items = NULL;
@@ -2801,9 +2802,9 @@ thunar_action_manager_create_document_submenu_templates (ThunarActionManager *ac
 
   /* sort items so that directories come before files and ancestors come
    * before descendants */
-  files = g_list_sort (files, (GCompareFunc) (void (*)(void)) thunar_file_compare_by_type);
+  files_sorted = g_list_sort (thunar_g_list_copy_deep (files), (GCompareFunc) (void (*)(void)) thunar_file_compare_by_type);
 
-  for (lp = g_list_first (files); lp != NULL; lp = lp->next)
+  for (lp = g_list_first (files_sorted); lp != NULL; lp = lp->next)
     {
       file = lp->data;
 
@@ -2848,6 +2849,8 @@ thunar_action_manager_create_document_submenu_templates (ThunarActionManager *ac
       cairo_surface_destroy (surface);
     }
 
+  g_list_free_full (files_sorted, g_object_unref);
+
   /* destroy lists */
   g_list_free (dirs);
   g_list_free (items);
-- 
GitLab