Skip to content

Commit 147a4c7

Browse files
authored
[rtsan] Fix issue where close test would lead to crash (#144017)
1 parent 89f692a commit 147a4c7

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,6 @@ TEST_F(RtsanFileTest, FcntlSetFdDiesWhenRealtime) {
449449
close(fd);
450450
}
451451

452-
TEST(TestRtsanInterceptors, CloseDiesWhenRealtime) {
453-
auto Func = []() { close(0); };
454-
ExpectRealtimeDeath(Func, "close");
455-
ExpectNonRealtimeSurvival(Func);
456-
}
457-
458452
TEST(TestRtsanInterceptors, ChdirDiesWhenRealtime) {
459453
auto Func = []() { chdir("."); };
460454
ExpectRealtimeDeath(Func, "chdir");
@@ -606,8 +600,10 @@ class RtsanOpenedFileTest : public RtsanFileTest {
606600
}
607601

608602
void TearDown() override {
609-
if (file != nullptr)
603+
const bool is_open = fcntl(fd, F_GETFD) != -1;
604+
if (is_open && file != nullptr)
610605
fclose(file);
606+
611607
RtsanFileTest::TearDown();
612608
}
613609

@@ -620,6 +616,16 @@ class RtsanOpenedFileTest : public RtsanFileTest {
620616
int fd = -1;
621617
};
622618

619+
TEST_F(RtsanOpenedFileTest, CloseDiesWhenRealtime) {
620+
auto Func = [this]() { close(GetOpenFd()); };
621+
ExpectRealtimeDeath(Func, "close");
622+
}
623+
624+
TEST_F(RtsanOpenedFileTest, CloseSurvivesWhenNotRealtime) {
625+
auto Func = [this]() { close(GetOpenFd()); };
626+
ExpectNonRealtimeSurvival(Func);
627+
}
628+
623629
#if SANITIZER_INTERCEPT_FSEEK
624630
TEST_F(RtsanOpenedFileTest, FgetposDieWhenRealtime) {
625631
auto Func = [this]() {

0 commit comments

Comments
 (0)