[Lldb-commits] [lldb] r178738 - Change EnumerateDirectory from using readdir() to using readdir_r()
Jason Molenda
jmolenda at apple.com
Wed Apr 3 20:19:28 PDT 2013
Author: jmolenda
Date: Wed Apr 3 22:19:27 2013
New Revision: 178738
URL: http://llvm.org/viewvc/llvm-project?rev=178738&view=rev
Log:
Change EnumerateDirectory from using readdir() to using readdir_r()
so it can be re-entered while iterating over a directory safely.
Modified:
lldb/trunk/source/Host/common/FileSpec.cpp
Modified: lldb/trunk/source/Host/common/FileSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/FileSpec.cpp?rev=178738&r1=178737&r2=178738&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/FileSpec.cpp (original)
+++ lldb/trunk/source/Host/common/FileSpec.cpp Wed Apr 3 22:19:27 2013
@@ -891,8 +891,15 @@ FileSpec::EnumerateDirectory
lldb_utility::CleanUp <DIR *, int> dir_path_dir (opendir(dir_path), NULL, closedir);
if (dir_path_dir.is_valid())
{
- struct dirent* dp;
- while ((dp = readdir(dir_path_dir.get())) != NULL)
+ long path_max = fpathconf (dirfd (dir_path_dir.get()), _PC_NAME_MAX);
+#if defined (__APPLE_) && defined (__DARWIN_MAXPATHLEN)
+ if (path_max < __DARWIN_MAXPATHLEN)
+ path_max = __DARWIN_MAXPATHLEN;
+#endif
+ struct dirent *buf, *dp;
+ buf = (struct dirent *) malloc (offsetof (struct dirent, d_name) + path_max + 1);
+
+ while (buf && readdir_r(dir_path_dir.get(), buf, &dp) == 0 && dp)
{
// Only search directories
if (dp->d_type == DT_DIR || dp->d_type == DT_UNKNOWN)
@@ -969,6 +976,10 @@ FileSpec::EnumerateDirectory
}
}
}
+ if (buf)
+ {
+ free (buf);
+ }
}
}
// By default when exiting a directory, we tell the parent enumeration
More information about the lldb-commits
mailing list