From d609d342a5d48f47b05dc5d9e348cdb6e000ab64 Mon Sep 17 00:00:00 2001
From: Theo Linkspfeifer <lastonestanding@tutanota.com>
Date: Fri, 17 Jun 2022 23:28:11 +0200
Subject: [PATCH] Fix memory leak (Issue #573)

Co-authored-by: Alexander Schwinn <alexxcons@xfce.org>
---
 thunar/thunar-window.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c
index b00c61a2e..375c401e2 100644
--- a/thunar/thunar-window.c
+++ b/thunar/thunar-window.c
@@ -5726,6 +5726,8 @@ static void
 thunar_window_location_toolbar_add_ucas (ThunarWindow *window)
 {
   ThunarxProviderFactory *provider_factory;
+  ThunarFile             *home_folder;
+  GFile                  *home_gfile;
   GList                  *providers;
   GList                  *thunarx_menu_items = NULL;
   GList                  *lp_provider;
@@ -5733,6 +5735,13 @@ thunar_window_location_toolbar_add_ucas (ThunarWindow *window)
   GList                  *toolbar_container_children;
   guint                   item_count;
 
+  /* determine the file for the home directory */
+  home_gfile = thunar_g_file_new_for_home ();
+  home_folder = thunar_file_get (home_gfile, NULL);
+  g_object_unref (home_gfile);
+  if (home_folder == NULL)
+    return;
+
   /* get number of items in the toolbar */
   toolbar_container_children = gtk_container_get_children (GTK_CONTAINER (window->location_toolbar));
   item_count = g_list_length (toolbar_container_children);
@@ -5748,7 +5757,8 @@ thunar_window_location_toolbar_add_ucas (ThunarWindow *window)
       /* load the menu items offered by the menu providers */
       for (lp_provider = providers; lp_provider != NULL; lp_provider = lp_provider->next)
         {
-          thunarx_menu_items = thunarx_menu_provider_get_folder_menu_items (lp_provider->data, GTK_WIDGET (window), THUNARX_FILE_INFO (thunar_file_get (thunar_g_file_new_for_home (), NULL)));
+          thunarx_menu_items = thunarx_menu_provider_get_folder_menu_items (lp_provider->data, GTK_WIDGET (window),
+                                                                            THUNARX_FILE_INFO (home_folder));
 
           for (lp_item = thunarx_menu_items; lp_item != NULL; lp_item = lp_item->next)
             {
@@ -5779,8 +5789,11 @@ thunar_window_location_toolbar_add_ucas (ThunarWindow *window)
 
           g_list_free_full (thunarx_menu_items, g_object_unref);
         }
+
       g_list_free_full (providers, g_object_unref);
     }
+
+  g_object_unref (home_folder);
 }
 
 
-- 
GitLab