@@ -73,7 +73,6 @@ class TestLeakAutoVar : public TestFixture {
73
73
TEST_CASE (realloc5); // #9292, #9990
74
74
TEST_CASE (freopen1);
75
75
TEST_CASE (freopen2);
76
- TEST_CASE (fdopen); // #12781
77
76
78
77
TEST_CASE (deallocuse1);
79
78
TEST_CASE (deallocuse3);
@@ -761,22 +760,6 @@ class TestLeakAutoVar : public TestFixture {
761
760
ASSERT_EQUALS (" [test.c:4]: (error) Resource leak: q\n " , errout_str ());
762
761
}
763
762
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
-
780
763
void deallocuse1 () {
781
764
check (" void f(char *p) {\n "
782
765
" free(p);\n "
@@ -3384,6 +3367,7 @@ class TestLeakAutoVarPosix : public TestFixture {
3384
3367
void run () override {
3385
3368
TEST_CASE (memleak_getline);
3386
3369
TEST_CASE (deallocuse_fdopen);
3370
+ TEST_CASE (doublefree_fdopen); // #12781
3387
3371
}
3388
3372
3389
3373
void memleak_getline () {
@@ -3409,6 +3393,22 @@ class TestLeakAutoVarPosix : public TestFixture {
3409
3393
" }\n " );
3410
3394
ASSERT_EQUALS (" " , errout_str ());
3411
3395
}
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
+ }
3412
3412
};
3413
3413
3414
3414
REGISTER_TEST (TestLeakAutoVarPosix)
0 commit comments