summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Path.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r--llvm/lib/Support/Path.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index d4b9d02e030..f229f23a4f8 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -1099,8 +1099,14 @@ Error TempFile::keep(const Twine &Name) {
std::error_code RenameEC = cancelDeleteOnClose(FD);
if (!RenameEC)
RenameEC = rename_fd(FD, Name);
+ // If we can't rename, discard the temporary file.
+ if (RenameEC)
+ removeFD(FD);
#else
std::error_code RenameEC = fs::rename(TmpName, Name);
+ // If we can't rename, discard the temporary file.
+ if (RenameEC)
+ remove(TmpName);
sys::DontRemoveFileOnSignal(TmpName);
#endif
OpenPOWER on IntegriCloud