Skip to content
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
34 changes: 17 additions & 17 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class TestLeakAutoVar : public TestFixture {
TEST_CASE(realloc5); // #9292, #9990
TEST_CASE(freopen1);
TEST_CASE(freopen2);
TEST_CASE(fdopen); // #12781

TEST_CASE(deallocuse1);
TEST_CASE(deallocuse3);
Expand Down Expand Up @@ -761,22 +760,6 @@ class TestLeakAutoVar : public TestFixture {
ASSERT_EQUALS("[test.c:4]: (error) Resource leak: q\n", errout_str());
}

void fdopen() { // #12781
check("void foo(void) {\n"
" int fd;\n"
" FILE *stream;\n"
" fd = open(\"/foo\", O_RDONLY);\n"
" if (fd == -1) return;\n"
" stream = fdopen(fd, \"r\");\n"
" if (!stream) {\n"
" close(fd);\n"
" return;\n"
" }\n"
" fclose(stream);\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}

void deallocuse1() {
check("void f(char *p) {\n"
" free(p);\n"
Expand Down Expand Up @@ -3384,6 +3367,7 @@ class TestLeakAutoVarPosix : public TestFixture {
void run() override {
TEST_CASE(memleak_getline);
TEST_CASE(deallocuse_fdopen);
TEST_CASE(doublefree_fdopen); // #12781
}

void memleak_getline() {
Expand All @@ -3409,6 +3393,22 @@ class TestLeakAutoVarPosix : public TestFixture {
"}\n");
ASSERT_EQUALS("", errout_str());
}

void doublefree_fdopen() { // #12781
check("void foo(void) {\n"
" int fd;\n"
" FILE *stream;\n"
" fd = open(\"/foo\", O_RDONLY);\n"
" if (fd == -1) return;\n"
" stream = fdopen(fd, \"r\");\n"
" if (!stream) {\n"
" close(fd);\n"
" return;\n"
" }\n"
" fclose(stream);\n"
"}\n");
ASSERT_EQUALS("", errout_str());
}
};

REGISTER_TEST(TestLeakAutoVarPosix)