From 9810bad869cafef3dfbb864d58e035d837e34200 Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Fri, 2 Jun 2023 10:32:33 +0200 Subject: [PATCH] #9708 (doublefree) - Added a regression test (#5109) --- test/testleakautovar.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 7373d23d5..7560c2b08 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -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 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 x(i);\n" + "}", true); + ASSERT_EQUALS("", errout.str()); + } + void exit1() { check("void f() {\n" " char *p = malloc(10);\n"