#9708 (doublefree) - Added a regression test (#5109)

This commit is contained in:
orbitcowboy 2023-06-02 10:32:33 +02:00 committed by GitHub
parent c636641e67
commit 9810bad869
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 0 deletions

View File

@ -125,6 +125,7 @@ private:
TEST_CASE(doublefree11);
TEST_CASE(doublefree12); // #10502
TEST_CASE(doublefree13); // #11008
TEST_CASE(doublefree14); // #9708
// exit
TEST_CASE(exit1);
@ -1454,6 +1455,27 @@ private:
ASSERT_EQUALS("", errout.str());
}
void doublefree14() { // #9708
check("using namespace std;\n"
" \n"
"int main()\n"
"{\n"
" int *i = new int;\n"
" unique_ptr<int> x(i);\n"
" delete i;\n"
"}", true);
ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:7]: (error) Memory pointed to by 'i' is freed twice.\n", errout.str());
check("using namespace std;\n"
" \n"
"int main()\n"
"{\n"
" int *i = new int;\n"
" unique_ptr<int> x(i);\n"
"}", true);
ASSERT_EQUALS("", errout.str());
}
void exit1() {
check("void f() {\n"
" char *p = malloc(10);\n"