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

This commit is contained in:
Chris Apple
2025-06-15 06:54:11 -07:00
committed by GitHub
parent 89f692a24f
commit 147a4c7743

View File

@@ -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");
@@ -606,8 +600,10 @@ protected:
}
void TearDown() override {
if (file != nullptr)
const bool is_open = fcntl(fd, F_GETFD) != -1;
if (is_open && file != nullptr)
fclose(file);
RtsanFileTest::TearDown();
}
@@ -620,6 +616,16 @@ private:
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]() {