diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index a873e469c..42f2416f1 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -112,6 +112,7 @@ private: TEST_CASE(deallocuse8); // #1765 TEST_CASE(deallocuse9); // #9781 TEST_CASE(deallocuse10); + TEST_CASE(deallocuse11); // #8302 TEST_CASE(doublefree1); TEST_CASE(doublefree2); @@ -840,6 +841,22 @@ private: 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"