[PATCH] D63087: [Path] Set FD to -1 in moved-from TempFile
Jonas Devlieghere via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 10 12:09:17 PDT 2019
JDevlieghere created this revision.
JDevlieghere added reviewers: shafik, Bigcheese.
Herald added subscribers: kristina, dexonsmith, hiraditya.
Herald added a project: LLVM.
When moving a temp file, explicitly set the file descriptor to -1 so we can never accidentally close the moved-from TempFile.
Repository:
rL LLVM
https://reviews.llvm.org/D63087
Files:
llvm/lib/Support/Path.cpp
llvm/unittests/Support/Path.cpp
Index: llvm/unittests/Support/Path.cpp
===================================================================
--- llvm/unittests/Support/Path.cpp
+++ llvm/unittests/Support/Path.cpp
@@ -578,6 +578,7 @@
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 @@
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"));
Index: llvm/lib/Support/Path.cpp
===================================================================
--- llvm/lib/Support/Path.cpp
+++ llvm/lib/Support/Path.cpp
@@ -1125,6 +1125,7 @@
TmpName = std::move(Other.TmpName);
FD = Other.FD;
Other.Done = true;
+ Other.FD = -1;
return *this;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63087.203870.patch
Type: text/x-patch
Size: 1220 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190610/f6ccdad2/attachment.bin>
More information about the llvm-commits
mailing list