From 932cabdb3407d28d7c2399063e1deb4a3ce1fc2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 31 Oct 2024 11:19:41 +0100 Subject: [PATCH 1/2] load posix.cfg in TestLeakAutoVar::fdopen --- test/testleakautovar.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 3e17e70288e..ccfd155a1ee 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -762,6 +762,7 @@ class TestLeakAutoVar : public TestFixture { } void fdopen() { // #12781 + const Settings posixSettings = settingsBuilder().library("posix.cfg").build(); check("void foo(void) {\n" " int fd;\n" " FILE *stream;\n" @@ -773,7 +774,7 @@ class TestLeakAutoVar : public TestFixture { " return;\n" " }\n" " fclose(stream);\n" - "}\n"); + "}\n", posixSettings); ASSERT_EQUALS("", errout_str()); } From 28efb859903135af574cce18e779286b480d21be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Thu, 31 Oct 2024 18:18:25 +0100 Subject: [PATCH 2/2] move test --- test/testleakautovar.cpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index ccfd155a1ee..4f3e054f542 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -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); @@ -761,23 +760,6 @@ class TestLeakAutoVar : public TestFixture { ASSERT_EQUALS("[test.c:4]: (error) Resource leak: q\n", errout_str()); } - void fdopen() { // #12781 - const Settings posixSettings = settingsBuilder().library("posix.cfg").build(); - 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", posixSettings); - ASSERT_EQUALS("", errout_str()); - } - void deallocuse1() { check("void f(char *p) {\n" " free(p);\n" @@ -3385,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() { @@ -3410,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)