From 64581a94ceeb3f3d3121823fbd309a8c81c8b4fb Mon Sep 17 00:00:00 2001
From: wang xiaomeng <wxiaomeng2016@gmail.com>
Date: Tue, 18 Jul 2023 09:04:19 +0000
Subject: [PATCH] Fix various memory leaks

Valgrind detects various memory leaks in gvfs daemons. Let's fix some of them.

Fixes: https://gitlab.gnome.org/GNOME/gvfs/-/issues/682
---
 common/gvfsmountinfo.c                  | 2 +-
 daemon/gvfsbackendnetwork.c             | 9 +--------
 daemon/gvfsdaemon.c                     | 3 +++
 monitor/gphoto2/ggphoto2volumemonitor.c | 1 +
 4 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/common/gvfsmountinfo.c b/common/gvfsmountinfo.c
index c3f31af..287b9db 100644
--- a/common/gvfsmountinfo.c
+++ b/common/gvfsmountinfo.c
@@ -640,7 +640,7 @@ _g_find_file_insensitive_async (GFile              *parent,
                            G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT,
                            cancellable,
                            find_file_insensitive_exists_callback, task);
-
+  g_object_unref (direct_file);
 
 }
 
diff --git a/daemon/gvfsbackendnetwork.c b/daemon/gvfsbackendnetwork.c
index 87cfec7..50cdc27 100644
--- a/daemon/gvfsbackendnetwork.c
+++ b/daemon/gvfsbackendnetwork.c
@@ -902,14 +902,7 @@ g_vfs_backend_network_init (GVfsBackendNetwork *network_backend)
       network_backend->smb_settings = g_settings_new ("org.gnome.system.smb");
 
       current_workgroup = g_settings_get_string (network_backend->smb_settings, "workgroup");
-
-      if (current_workgroup == NULL ||
-          current_workgroup[0] == 0) 
-        /* it's okay if current_workgroup is null here, 
-         * it's checked before the NetworkFile is added anyway. */
-        network_backend->current_workgroup = NULL;
-      else 
-        network_backend->current_workgroup = current_workgroup;
+      network_backend->current_workgroup = current_workgroup;
 
       g_signal_connect (network_backend->smb_settings,
                         "change-event",
diff --git a/daemon/gvfsdaemon.c b/daemon/gvfsdaemon.c
index a6d6236..f659041 100644
--- a/daemon/gvfsdaemon.c
+++ b/daemon/gvfsdaemon.c
@@ -145,6 +145,9 @@ g_vfs_daemon_finalize (GObject *object)
 
   daemon = G_VFS_DAEMON (object);
 
+  if (daemon->thread_pool != NULL)
+    g_thread_pool_free (daemon->thread_pool, TRUE, FALSE);
+
   /* There may be some jobs outstanding if we've been force unmounted. */
   if (daemon->jobs)
     g_warning ("daemon->jobs != NULL when finalizing daemon!");
diff --git a/monitor/gphoto2/ggphoto2volumemonitor.c b/monitor/gphoto2/ggphoto2volumemonitor.c
index 54dec6e..77d458a 100644
--- a/monitor/gphoto2/ggphoto2volumemonitor.c
+++ b/monitor/gphoto2/ggphoto2volumemonitor.c
@@ -331,6 +331,7 @@ gudev_coldplug_cameras (GGPhoto2VolumeMonitor *monitor)
         if (g_udev_device_has_property (d, "ID_GPHOTO2"))
             gudev_add_camera (monitor, d, FALSE);
     }
+    g_list_free_full (usb_devices, g_object_unref);
 }
 
 static GObject *
-- 
2.33.0

