[Support][Path] Don't inf loop if creating the parent directory fails.
authorMichael J. Spencer <bigcheesegs@gmail.com>
Tue, 12 Mar 2013 22:32:39 +0000 (22:32 +0000)
committerMichael J. Spencer <bigcheesegs@gmail.com>
Tue, 12 Mar 2013 22:32:39 +0000 (22:32 +0000)
Patch by Paul Robinson.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@176908 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/Windows/PathV2.inc

index 2e6cc96e7f141dbea2051761d30d48e42f3c3fb0..823f7583dacd73958af8c911094bc0220e52b6be 100644 (file)
@@ -593,6 +593,10 @@ retry_random_path:
   random_path_utf16.push_back(0);
   random_path_utf16.pop_back();
 
+  // Make sure we don't fall into an infinite loop by constantly trying
+  // to create the parent path.
+  bool TriedToCreateParent = false;
+
   // Try to create + open the path.
 retry_create_file:
   HANDLE TempFileHandle = ::CreateFileW(random_path_utf16.begin(),
@@ -610,7 +614,9 @@ retry_create_file:
     if (ec == windows_error::file_exists)
       goto retry_random_path;
     // Check for non-existing parent directories.
-    if (ec == windows_error::path_not_found) {
+    if (ec == windows_error::path_not_found && !TriedToCreateParent) {
+      TriedToCreateParent = true;
+
       // Create the directories using result_path as temp storage.
       if (error_code ec = UTF16ToUTF8(random_path_utf16.begin(),
                                       random_path_utf16.size(), result_path))