[lld] r222799 - [PECOFF] Properly close a file descriptor.

Rui Ueyama ruiu at google.com
Tue Nov 25 16:21:27 PST 2014


Author: ruiu
Date: Tue Nov 25 18:21:27 2014
New Revision: 222799

URL: http://llvm.org/viewvc/llvm-project?rev=222799&view=rev
Log:
[PECOFF] Properly close a file descriptor.

This was basically benign resource leak on Unix, but on Windows
it could cause builds to fail because opened file descriptor
prevents other processes from moving or removing the file.

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/PDBPass.h

Modified: lld/trunk/lib/ReaderWriter/PECOFF/PDBPass.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/PDBPass.h?rev=222799&r1=222798&r2=222799&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/PDBPass.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/PDBPass.h Tue Nov 25 18:21:27 2014
@@ -13,6 +13,12 @@
 #include "lld/Core/Pass.h"
 #include "llvm/ADT/StringRef.h"
 
+#if !defined(_MSC_VER) && !defined(__MINGW32__)
+#include <unistd.h>
+#else
+#include <io.h>
+#endif
+
 namespace lld {
 namespace pecoff {
 
@@ -30,6 +36,7 @@ private:
     int fd;
     if (llvm::sys::fs::openFileForWrite(path, fd, llvm::sys::fs::F_Append))
       llvm::report_fatal_error("failed to create a PDB file");
+    ::close(fd);
   }
 
   PECOFFLinkingContext &_ctx;





More information about the llvm-commits mailing list