From e3b401e8dfd6bfb668113fe0095a3e05566df068 Mon Sep 17 00:00:00 2001
From: houlifei <houlifei@uniontech.com>
Date: Thu, 20 Jul 2023 17:49:16 +0800
Subject: [PATCH] Fix memory leaks detected by valgrind

---
 common/gvfsmountinfo.c                  |  1 +
 daemon/gvfsbackendnetwork.c             | 10 ++--------
 daemon/gvfsdaemon.c                     |  3 +++
 monitor/gphoto2/ggphoto2volumemonitor.c |  1 +
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/common/gvfsmountinfo.c b/common/gvfsmountinfo.c
index c3f31af..34a5450 100644
--- a/common/gvfsmountinfo.c
+++ b/common/gvfsmountinfo.c
@@ -641,6 +641,7 @@ _g_find_file_insensitive_async (GFile              *parent,
                            cancellable,
                            find_file_insensitive_exists_callback, task);
 
+  g_object_unref (direct_file); //uos add for fixing memory leaks
 
 }
 
diff --git a/daemon/gvfsbackendnetwork.c b/daemon/gvfsbackendnetwork.c
index 87cfec7..9f1905b 100644
--- a/daemon/gvfsbackendnetwork.c
+++ b/daemon/gvfsbackendnetwork.c
@@ -902,19 +902,13 @@ 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",
                         G_CALLBACK (smb_settings_change_event_cb),
                         network_backend);
+      g_free (current_workgroup); // uos add for fixing memory leaks
     }
 
   if (network_backend->have_dnssd) 
diff --git a/daemon/gvfsdaemon.c b/daemon/gvfsdaemon.c
index a6d6236..72bdea1 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, TRUE); // uos add for fixing memory leaks
+
   /* 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..e689b41 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); // uos add for fixing memory leaks
 }
 
 static GObject *
-- 
2.33.0

