static internal IEnumerable<FileSystemInfo> EnumerateFileSystemInfos (string full, string searchPattern, SearchOption searchOption)
{
string path_with_pattern = Path.Combine (full, searchPattern);
- IntPtr handle;
+ IntPtr handle = IntPtr.Zero;
MonoIOError error;
FileAttributes rattr;
bool subdirs = searchOption == SearchOption.AllDirectories;
Path.Validate (full);
- string s = MonoIO.FindFirst (full, path_with_pattern, out rattr, out error, out handle);
- if (s == null)
- yield break;
- if (error != 0)
- throw MonoIO.GetException (Path.GetDirectoryName (path_with_pattern), (MonoIOError) error);
-
try {
+ string s = MonoIO.FindFirst (full, path_with_pattern, out rattr, out error, out handle);
+ if (s == null)
+ yield break;
+ if (error != 0)
+ throw MonoIO.GetException (Path.GetDirectoryName (path_with_pattern), (MonoIOError) error);
+
do {
if (((rattr & FileAttributes.ReparsePoint) == 0)){
if ((rattr & FileAttributes.Directory) != 0)
} while ((s = MonoIO.FindNext (handle, out rattr, out error)) != null);
} finally {
- MonoIO.FindClose (handle);
+ if (handle != IntPtr.Zero)
+ MonoIO.FindClose (handle);
}
}
ifh = g_new (IncrementalFind, 1);
ifh->find_handle = find_handle;
ifh->utf8_path = mono_string_to_utf8_checked (path, &error);
- if (mono_error_set_pending_exception (&error))
+ if (mono_error_set_pending_exception (&error)) {
+ MONO_ENTER_GC_SAFE;
+ FindClose (find_handle);
+ MONO_EXIT_GC_SAFE;
+ g_free (ifh);
return NULL;
+ }
ifh->domain = mono_domain_get ();
*handle = ifh;