@@ -73,7 +73,6 @@ class TestLeakAutoVar : public TestFixture {
7373 TEST_CASE (realloc5); // #9292, #9990
7474 TEST_CASE (freopen1);
7575 TEST_CASE (freopen2);
76- TEST_CASE (fdopen); // #12781
7776
7877 TEST_CASE (deallocuse1);
7978 TEST_CASE (deallocuse3);
@@ -761,22 +760,6 @@ class TestLeakAutoVar : public TestFixture {
761760 ASSERT_EQUALS (" [test.c:4]: (error) Resource leak: q\n " , errout_str ());
762761 }
763762
764- void fdopen () { // #12781
765- check (" void foo(void) {\n "
766- " int fd;\n "
767- " FILE *stream;\n "
768- " fd = open(\" /foo\" , O_RDONLY);\n "
769- " if (fd == -1) return;\n "
770- " stream = fdopen(fd, \" r\" );\n "
771- " if (!stream) {\n "
772- " close(fd);\n "
773- " return;\n "
774- " }\n "
775- " fclose(stream);\n "
776- " }\n " );
777- ASSERT_EQUALS (" " , errout_str ());
778- }
779-
780763 void deallocuse1 () {
781764 check (" void f(char *p) {\n "
782765 " free(p);\n "
@@ -3384,6 +3367,7 @@ class TestLeakAutoVarPosix : public TestFixture {
33843367 void run () override {
33853368 TEST_CASE (memleak_getline);
33863369 TEST_CASE (deallocuse_fdopen);
3370+ TEST_CASE (doublefree_fdopen); // #12781
33873371 }
33883372
33893373 void memleak_getline () {
@@ -3409,6 +3393,22 @@ class TestLeakAutoVarPosix : public TestFixture {
34093393 " }\n " );
34103394 ASSERT_EQUALS (" " , errout_str ());
34113395 }
3396+
3397+ void doublefree_fdopen () { // #12781
3398+ check (" void foo(void) {\n "
3399+ " int fd;\n "
3400+ " FILE *stream;\n "
3401+ " fd = open(\" /foo\" , O_RDONLY);\n "
3402+ " if (fd == -1) return;\n "
3403+ " stream = fdopen(fd, \" r\" );\n "
3404+ " if (!stream) {\n "
3405+ " close(fd);\n "
3406+ " return;\n "
3407+ " }\n "
3408+ " fclose(stream);\n "
3409+ " }\n " );
3410+ ASSERT_EQUALS (" " , errout_str ());
3411+ }
34123412};
34133413
34143414REGISTER_TEST (TestLeakAutoVarPosix)
0 commit comments