[glib/glib-2-72: 38/39] [PATCH] Add lock in _g_get_unix_mount_points() around *fsent() functions




commit 07b062b4dc7a41774f7698976d3108d7322ae175
Author: Rozhuk Ivan <rozhuk im gmail com>
Date:   Sat Jun 25 18:46:08 2022 +0300

    [PATCH] Add lock in _g_get_unix_mount_points() around *fsent() functions
    
    (cherry-picked from commit f43cf341511dd684a58c09e104e28c11987cbff1)

 gio/gunixmounts.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
---
diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c
index 9c8ef5d666..26963d623d 100644
--- a/gio/gunixmounts.c
+++ b/gio/gunixmounts.c
@@ -1408,17 +1408,13 @@ _g_get_unix_mount_points (void)
 {
   struct fstab *fstab = NULL;
   GUnixMountPoint *mount_point;
-  GList *return_list;
+  GList *return_list = NULL;
+  G_LOCK_DEFINE_STATIC (fsent);
 #ifdef HAVE_SYS_SYSCTL_H
   int usermnt = 0;
   struct stat sb;
 #endif
-  
-  if (!setfsent ())
-    return NULL;
 
-  return_list = NULL;
-  
 #ifdef HAVE_SYS_SYSCTL_H
 #if defined(HAVE_SYSCTLBYNAME)
   {
@@ -1446,7 +1442,14 @@ _g_get_unix_mount_points (void)
   }
 #endif
 #endif
-  
+
+  G_LOCK (fsent);
+  if (!setfsent ())
+    {
+      G_UNLOCK (fsent);
+      return NULL;
+    }
+
   while ((fstab = getfsent ()) != NULL)
     {
       gboolean is_read_only = FALSE;
@@ -1480,9 +1483,10 @@ _g_get_unix_mount_points (void)
 
       return_list = g_list_prepend (return_list, mount_point);
     }
-  
+
   endfsent ();
-  
+  G_UNLOCK (fsent);
+
   return g_list_reverse (return_list);
 }
 /* Interix {{{2 */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]