Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class TestLeakAutoVar : public TestFixture {
TEST_CASE(deallocuse8); // #1765
TEST_CASE(deallocuse9); // #9781
TEST_CASE(deallocuse10);
TEST_CASE(deallocuse11); // #8302

TEST_CASE(doublefree1);
TEST_CASE(doublefree2);
Expand Down Expand Up @@ -840,6 +841,22 @@ class TestLeakAutoVar : public TestFixture {
ASSERT_EQUALS("[test.c:2] -> [test.c:3]: (error) Returning/dereferencing 'p' after it is deallocated / released\n", errout.str());
}

void deallocuse11() { // #8302
check("int f() {\n"
" int *array = new int[42];\n"
" delete [] array;\n"
" return array[1];" // <<
"}", true);
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Returning/dereferencing 'array' after it is deallocated / released\n", errout.str());

check("int f() {\n"
" int *array = (int*)malloc(40);\n"
" free(array);\n"
" return array[1];" // <<
"}");
ASSERT_EQUALS("[test.c:3] -> [test.c:4]: (error) Returning/dereferencing 'array' after it is deallocated / released\n", errout.str());
}

void doublefree1() { // #3895
check("void f(char *p) {\n"
" if (x)\n"
Expand Down