Index: lib/Support/Path.cpp =================================================================== --- lib/Support/Path.cpp +++ lib/Support/Path.cpp @@ -1128,6 +1128,12 @@ Error TempFile::discard() { Done = true; + if (FD != -1 && close(FD) == -1) { + std::error_code EC = std::error_code(errno, std::generic_category()); + return errorCodeToError(EC); + } + FD = -1; + std::error_code RemoveEC; // On windows closing will remove the file. #ifndef _WIN32 @@ -1141,12 +1147,6 @@ if (!RemoveEC) TmpName = ""; - if (FD != -1 && close(FD) == -1) { - std::error_code EC = std::error_code(errno, std::generic_category()); - return errorCodeToError(EC); - } - FD = -1; - return errorCodeToError(RemoveEC); }