1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

On error, close the temporary file descriptor.

With this change llvm-ar can remove the temporary file on windows too.

llvm-svn: 186423
This commit is contained in:
Rafael Espindola 2013-07-16 16:00:32 +00:00
parent ebe95f88ed
commit 77c12b390e
2 changed files with 12 additions and 1 deletions

View File

@ -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

View File

@ -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));