From 1a4398a1986bd7c2fc34048cd07e6b221ebbd882 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 2 Sep 2016 01:10:53 +0000 Subject: 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 --- llvm/lib/Support/FileOutputBuffer.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'llvm/lib/Support/FileOutputBuffer.cpp') 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 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)); } -- cgit v1.2.3