[PECOFF] Properly close a file descriptor.
authorRui Ueyama <ruiu@google.com>
Wed, 26 Nov 2014 00:21:27 +0000 (00:21 +0000)
committerRui Ueyama <ruiu@google.com>
Wed, 26 Nov 2014 00:21:27 +0000 (00:21 +0000)
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.

llvm-svn: 222799

lld/lib/ReaderWriter/PECOFF/PDBPass.h

index 92199c9..0f7b292 100644 (file)
 #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;