@@ -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-
458452TEST(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
624630TEST_F(RtsanOpenedFileTest, FgetposDieWhenRealtime) {
625631 auto Func = [this]() {
0 commit comments