Skip to content

[rtsan] Fix issue where close test would lead to crash #144017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,6 @@ TEST_F(RtsanFileTest, FcntlSetFdDiesWhenRealtime) {
close(fd);
}

TEST(TestRtsanInterceptors, CloseDiesWhenRealtime) {
auto Func = []() { close(0); };
ExpectRealtimeDeath(Func, "close");
ExpectNonRealtimeSurvival(Func);
}

TEST(TestRtsanInterceptors, ChdirDiesWhenRealtime) {
auto Func = []() { chdir("."); };
ExpectRealtimeDeath(Func, "chdir");
Expand Down Expand Up @@ -606,8 +600,10 @@ class RtsanOpenedFileTest : public RtsanFileTest {
}

void TearDown() override {
if (file != nullptr)
const bool is_open = fcntl(fd, F_GETFD) != -1;
if (is_open && file != nullptr)
fclose(file);

RtsanFileTest::TearDown();
}

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

TEST_F(RtsanOpenedFileTest, CloseDiesWhenRealtime) {
auto Func = [this]() { close(GetOpenFd()); };
ExpectRealtimeDeath(Func, "close");
}

TEST_F(RtsanOpenedFileTest, CloseSurvivesWhenNotRealtime) {
auto Func = [this]() { close(GetOpenFd()); };
ExpectNonRealtimeSurvival(Func);
}

#if SANITIZER_INTERCEPT_FSEEK
TEST_F(RtsanOpenedFileTest, FgetposDieWhenRealtime) {
auto Func = [this]() {
Expand Down
Loading