@@ -100,7 +100,6 @@ class TestMemleak : private TestFixture {
100100 errout.str (" " );
101101
102102 Settings settings;
103- settings.standards .posix = true ;
104103
105104 Tokenizer tokenizer (&settings, this );
106105 std::istringstream istr (code);
@@ -330,7 +329,6 @@ class TestMemleakInFunction : public TestFixture {
330329 TEST_CASE (tmpfile_function);
331330 TEST_CASE (fcloseall_function);
332331 TEST_CASE (file_functions);
333- TEST_CASE (posix_rewinddir);
334332 TEST_CASE (getc_function);
335333
336334 TEST_CASE (open_function);
@@ -366,10 +364,6 @@ class TestMemleakInFunction : public TestFixture {
366364
367365 TEST_CASE (c_code);
368366
369- // test that the cfg files are configured correctly
370- TEST_CASE (posixcfg);
371- TEST_CASE (posixcfg_mmap);
372-
373367 TEST_CASE (gnucfg);
374368 }
375369
@@ -3700,22 +3694,13 @@ class TestMemleakInFunction : public TestFixture {
37003694 Settings settings;
37013695 settings.standards .posix = true ;
37023696
3703- check (" void f()\n "
3704- " {\n "
3697+ check (" void f() {\n "
37053698 " FILE *f = popen (\" test\" , \" w\" );\n "
37063699 " int a = pclose(f);\n "
37073700 " }" , &settings);
37083701 ASSERT_EQUALS (" " , errout.str ());
37093702 }
37103703
3711- void posix_rewinddir () {
3712- Settings settings;
3713- settings.standards .posix = true ;
3714-
3715- check (" void f(DIR *p) { rewinddir(p); }" , &settings);
3716- ASSERT_EQUALS (" " , errout.str ());
3717- }
3718-
37193704 void exit2 () {
37203705 check (" void f()\n "
37213706 " {\n "
@@ -4280,114 +4265,6 @@ class TestMemleakInFunction : public TestFixture {
42804265 check (code, &settings);
42814266 ASSERT_EQUALS (" [test.cpp:3]: (error) Memory leak: p\n " , errout.str ());
42824267 }
4283-
4284- // Test that posix.cfg is configured correctly
4285- void posixcfg () {
4286- Settings settings;
4287- settings.standards .posix = true ;
4288- LOAD_LIB_2 (settings.library , " posix.cfg" );
4289-
4290- const char code[] = " void leaks() {\n "
4291- " void* leak1 = fdopendir();\n "
4292- " void* leak2 = opendir();\n "
4293- " void* leak3 = socket();\n "
4294- " }\n "
4295- " void noleaks() {\n "
4296- " void *p1 = fdopendir(); closedir(p1);\n "
4297- " void *p2 = opendir(); closedir(p2);\n "
4298- " void *p3 = socket(); close(p3);\n "
4299- " }" ;
4300- check (code, &settings);
4301- ASSERT_EQUALS (" [test.cpp:5]: (error) Resource leak: leak1\n "
4302- " [test.cpp:5]: (error) Resource leak: leak2\n "
4303- " [test.cpp:5]: (error) Resource leak: leak3\n " , errout.str ());
4304-
4305- const char code2[] = " int main() {\n "
4306- " int fileDescriptor = socket(AF_INET, SOCK_STREAM, 0);\n "
4307- " close(fileDescriptor);\n "
4308- " }" ;
4309- check (code2, &settings);
4310- ASSERT_EQUALS (" " , errout.str ());
4311-
4312- // Ticket #2830
4313- check (" void f(const char *path) {\n "
4314- " int fd = open(path, O_RDONLY);\n "
4315- " FILE *f = fdopen(fd, x);\n "
4316- " fclose(f);\n "
4317- " }" , &settings);
4318- ASSERT_EQUALS (" " , errout.str ());
4319-
4320- // Ticket #1416
4321- check (" void f(void) {\n "
4322- " FILE *f = fdopen(0, \" r\" );\n "
4323- " }" , &settings);
4324- ASSERT_EQUALS (" [test.cpp:3]: (error) Resource leak: f\n " , errout.str ());
4325-
4326- // strdupa allocates on the stack, no free() needed
4327- check (" void x()\n "
4328- " {\n "
4329- " char *s = strdupa(\" Test\" );\n "
4330- " }" , &settings);
4331- ASSERT_EQUALS (" " , errout.str ());
4332-
4333- LOAD_LIB_2 (settings.library , " gtk.cfg" );
4334-
4335- check (" void f(char *a) {\n "
4336- " char *s = g_strdup(a);\n "
4337- " mkstemp(s);\n "
4338- " mkdtemp(s);\n "
4339- " mktemp(s);\n "
4340- " }" , &settings);
4341- ASSERT_EQUALS (" [test.cpp:6]: (error) Memory leak: s\n " , errout.str ());
4342- }
4343-
4344- void posixcfg_mmap () {
4345- Settings settings;
4346- settings.standards .posix = true ;
4347- LOAD_LIB_2 (settings.library , " posix.cfg" );
4348-
4349- // normal mmap
4350- check (" void f(int fd) {\n "
4351- " char *addr = mmap(NULL, 255, PROT_NONE, MAP_PRIVATE, fd, 0);\n "
4352- " munmap(addr, 255);\n "
4353- " }" , &settings);
4354- ASSERT_EQUALS (" " , errout.str ());
4355-
4356- // mmap64 - large file support
4357- check (" void f(int fd) {\n "
4358- " char *addr = mmap64(NULL, 255, PROT_NONE, MAP_PRIVATE, fd, 0);\n "
4359- " munmap(addr, 255);\n "
4360- " }" , &settings);
4361- ASSERT_EQUALS (" " , errout.str ());
4362-
4363- // pass in fixed address
4364- check (" void f(int fd) {\n "
4365- " void *fixed_addr = 123;\n "
4366- " void *mapped_addr = mmap(fixed_addr, 255, PROT_NONE, MAP_PRIVATE, fd, 0);\n "
4367- " munmap(mapped_addr, 255);\n "
4368- " }" , &settings);
4369- ASSERT_EQUALS (" " , errout.str ());
4370-
4371- // no munmap()
4372- check (" void f(int fd) {\n "
4373- " void *addr = mmap(NULL, 255, PROT_NONE, MAP_PRIVATE, fd, 0);\n "
4374- " }" , &settings);
4375- ASSERT_EQUALS (" [test.cpp:3]: (error) Memory leak: addr\n " , errout.str ());
4376-
4377- // wrong deallocator
4378- check (" void f(int fd) {\n "
4379- " void *addr = mmap(NULL, 255, PROT_NONE, MAP_PRIVATE, fd, 0);\n "
4380- " free(addr);\n "
4381- " }" , &settings);
4382- ASSERT_EQUALS (" [test.cpp:3]: (error) Mismatching allocation and deallocation: addr\n " , errout.str ());
4383-
4384- // wrong deallocator for mmap64
4385- check (" void f(int fd) {\n "
4386- " void *addr = mmap64(NULL, 255, PROT_NONE, MAP_PRIVATE, fd, 0);\n "
4387- " free(addr);\n "
4388- " }" , &settings);
4389- ASSERT_EQUALS (" [test.cpp:3]: (error) Mismatching allocation and deallocation: addr\n " , errout.str ());
4390- }
43914268};
43924269
43934270static TestMemleakInFunction testMemleakInFunction;
@@ -6313,7 +6190,6 @@ class TestMemleakNoVar : public TestFixture {
63136190 }
63146191
63156192 void run () {
6316- settings.standards .posix = true ;
63176193 settings.inconclusive = true ;
63186194 settings.addEnabled (" warning" );
63196195
0 commit comments