summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-07-16 16:00:32 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-07-16 16:00:32 +0000
commit7303af37b78912c58d3dd14d2b6965898c31ab9b (patch)
tree310e43f36f95a21098c0c59e178989096d03b10c
parent0dbabb52a46d287d2381706c135fce222065c37d (diff)
downloadbcm5719-llvm-7303af37b78912c58d3dd14d2b6965898c31ab9b.tar.gz
bcm5719-llvm-7303af37b78912c58d3dd14d2b6965898c31ab9b.zip
On error, close the temporary file descriptor.
With this change llvm-ar can remove the temporary file on windows too. llvm-svn: 186423
-rw-r--r--llvm/test/Object/archive-error-tmp.txt9
-rw-r--r--llvm/tools/llvm-ar/llvm-ar.cpp4
2 files changed, 12 insertions, 1 deletions
diff --git a/llvm/test/Object/archive-error-tmp.txt b/llvm/test/Object/archive-error-tmp.txt
new file mode 100644
index 00000000000..061898655b6
--- /dev/null
+++ b/llvm/test/Object/archive-error-tmp.txt
@@ -0,0 +1,9 @@
+REQUIRES: shell
+
+Test that no temporary file is left behind on error.
+
+RUN: rm -rf %t
+RUN: mkdir %t
+RUN: not llvm-ar rc %t/foo.a .
+RUN: rmdir %t
+
diff --git a/llvm/tools/llvm-ar/llvm-ar.cpp b/llvm/tools/llvm-ar/llvm-ar.cpp
index 32bcb49a1db..d65f9ecc9fe 100644
--- a/llvm/tools/llvm-ar/llvm-ar.cpp
+++ b/llvm/tools/llvm-ar/llvm-ar.cpp
@@ -41,10 +41,13 @@ using namespace llvm;
static StringRef ToolName;
static const char *TemporaryOutput;
+static int TmpArchiveFD = -1;
// fail - Show the error message and exit.
LLVM_ATTRIBUTE_NORETURN static void fail(Twine Error) {
outs() << ToolName << ": " << Error << ".\n";
+ if (TmpArchiveFD != -1)
+ close(TmpArchiveFD);
if (TemporaryOutput)
sys::fs::remove(TemporaryOutput);
exit(1);
@@ -526,7 +529,6 @@ static void printWithSpacePadding(raw_ostream &OS, T Data, unsigned Size) {
static void performWriteOperation(ArchiveOperation Operation,
object::Archive *OldArchive) {
- int TmpArchiveFD;
SmallString<128> TmpArchive;
failIfError(sys::fs::createUniqueFile(ArchiveName + ".temp-archive-%%%%%%%.a",
TmpArchiveFD, TmpArchive));
OpenPOWER on IntegriCloud