Skip to content

Commit

Permalink
Add test for #9695
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Dec 2, 2023
1 parent bab1807 commit bb8e9e4
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class TestLeakAutoVar : public TestFixture {
TEST_CASE(deallocuse10);
TEST_CASE(deallocuse11); // #8302
TEST_CASE(deallocuse12);
TEST_CASE(deallocuse13);

TEST_CASE(doublefree1);
TEST_CASE(doublefree2);
Expand Down Expand Up @@ -895,6 +896,20 @@ class TestLeakAutoVar : public TestFixture {
ASSERT_EQUALS("", errout.str());
}

void deallocuse13() {
check("void f() {\n" // #9695
" auto* a = new int[2];\n"
" delete[] a;\n"
" a[1] = 0;\n"
" auto* b = static_cast<int*>(malloc(8));\n"
" free(b);\n"
" b[1] = 0;\n"
"}\n", true);
ASSERT_EQUALS("[test.cpp:4]: (error) Dereferencing 'a' after it is deallocated / released\n"
"[test.cpp:7]: (error) Dereferencing 'b' after it is deallocated / released\n",
errout.str());
}

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

0 comments on commit bb8e9e4

Please sign in to comment.