Skip to content

Commit 1fbaae9

Browse files
committed
Added regression test cases for cppcheck-opensource#404.
1 parent 4b1075b commit 1fbaae9

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

test/testleakautovar.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class TestLeakAutoVar : public TestFixture {
9494
TEST_CASE(configuration2);
9595
TEST_CASE(configuration3);
9696
TEST_CASE(configuration4);
97+
98+
TEST_CASE(ptrptr);
9799
}
98100

99101
void check(const char code[]) {
@@ -545,6 +547,13 @@ class TestLeakAutoVar : public TestFixture {
545547
"}");
546548
ASSERT_EQUALS("[test.c:4]: (information) set_data configuration is needed to establish if there is a leak or not\n", errout.str());
547549
}
550+
551+
void ptrptr() {
552+
check("void f() {\n"
553+
" char **p = malloc(10);\n"
554+
"}");
555+
ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p\n", errout.str());
556+
}
548557
};
549558

550559
REGISTER_TEST(TestLeakAutoVar)

test/testmemleak.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ class TestMemleakInFunction : public TestFixture {
353353
TEST_CASE(trac1879);
354354

355355
TEST_CASE(garbageCode);
356+
357+
TEST_CASE(ptrptr);
356358
}
357359

358360

@@ -3800,6 +3802,15 @@ class TestMemleakInFunction : public TestFixture {
38003802
"}");
38013803
}
38023804

3805+
void ptrptr() {
3806+
check("void f() {\n"
3807+
" char *p;\n"
3808+
" char **pp = &p;\n"
3809+
" *pp = calloc(10);\n"
3810+
"}");
3811+
ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str());
3812+
}
3813+
38033814
};
38043815

38053816
static TestMemleakInFunction testMemleakInFunction;

0 commit comments

Comments
 (0)