1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 12:43:36 +01:00

[Path] Set FD to -1 in moved-from TempFile

When moving a temp file, explicitly set the file descriptor to -1 so we
can never accidentally close the moved-from TempFile.

Differential revision: https://reviews.llvm.org/D63087

llvm-svn: 363083
This commit is contained in:
Jonas Devlieghere 2019-06-11 16:42:42 +00:00
parent e131342efa
commit 6359609b7d
2 changed files with 3 additions and 0 deletions

View File

@ -1125,6 +1125,7 @@ TempFile &TempFile::operator=(TempFile &&Other) {
TmpName = std::move(Other.TmpName);
FD = Other.FD;
Other.Done = true;
Other.FD = -1;
return *this;
}

View File

@ -578,6 +578,7 @@ TEST_F(FileSystemTest, TempFileKeepDiscard) {
auto TempFileOrError = fs::TempFile::create(TestDirectory + "/test-%%%%");
ASSERT_TRUE((bool)TempFileOrError);
fs::TempFile File = std::move(*TempFileOrError);
ASSERT_EQ(-1, TempFileOrError->FD);
ASSERT_FALSE((bool)File.keep(TestDirectory + "/keep"));
ASSERT_FALSE((bool)File.discard());
ASSERT_TRUE(fs::exists(TestDirectory + "/keep"));
@ -589,6 +590,7 @@ TEST_F(FileSystemTest, TempFileDiscardDiscard) {
auto TempFileOrError = fs::TempFile::create(TestDirectory + "/test-%%%%");
ASSERT_TRUE((bool)TempFileOrError);
fs::TempFile File = std::move(*TempFileOrError);
ASSERT_EQ(-1, TempFileOrError->FD);
ASSERT_FALSE((bool)File.discard());
ASSERT_FALSE((bool)File.discard());
ASSERT_FALSE(fs::exists(TestDirectory + "/keep"));