diff options
author | Reid Kleckner <rnk@google.com> | 2016-09-02 01:10:53 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2016-09-02 01:10:53 +0000 |
commit | 1a4398a1986bd7c2fc34048cd07e6b221ebbd882 (patch) | |
tree | 559de5b30cd25d7d82da0bb90d836ccff9f8c38c /llvm/lib/Support/FileOutputBuffer.cpp | |
parent | d4e80a9615639942f62ac808cdb195105218f813 (diff) | |
download | bcm5719-llvm-1a4398a1986bd7c2fc34048cd07e6b221ebbd882.tar.gz bcm5719-llvm-1a4398a1986bd7c2fc34048cd07e6b221ebbd882.zip |
Fix a real temp file leak in FileOutputBuffer
If we failed to commit the buffer but did not die to a signal, the temp
file would remain on disk on Windows. Having an open file mapping and
file handle prevents the file from being deleted. I am choosing not to
add an assertion of success on the temp file removal, since virus
scanners and other environmental things can often cause removal to fail
in real world tools.
Also fix more temp file leaks in unit tests.
llvm-svn: 280445
Diffstat (limited to 'llvm/lib/Support/FileOutputBuffer.cpp')
-rw-r--r-- | llvm/lib/Support/FileOutputBuffer.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/llvm/lib/Support/FileOutputBuffer.cpp b/llvm/lib/Support/FileOutputBuffer.cpp index 651e679f2cb..2c7bf0435d8 100644 --- a/llvm/lib/Support/FileOutputBuffer.cpp +++ b/llvm/lib/Support/FileOutputBuffer.cpp @@ -32,6 +32,9 @@ FileOutputBuffer::FileOutputBuffer(std::unique_ptr<mapped_file_region> R, : Region(std::move(R)), FinalPath(Path), TempPath(TmpPath) {} FileOutputBuffer::~FileOutputBuffer() { + // Close the mapping before deleting the temp file, so that the removal + // succeeds. + Region.reset(); sys::fs::remove(Twine(TempPath)); } |