From bad66594d60acbb384a838d5d98dd8e376689987 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sat, 21 Apr 2018 04:24:19 -0500 Subject: [PATCH] Fix double free regression with smart pointers (#1184) --- lib/checkleakautovar.cpp | 2 +- test/testleakautovar.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 08ff25743..ff37165f9 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -562,7 +562,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, const Token * typeEndTok = ftok->linkAt(1); - if (!Token::Match(typeEndTok, "> %var% {|( %var%")) + if (!Token::Match(typeEndTok, "> %var% {|( %var% ,|)|}")) continue; bool arrayDelete = false; diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 208bbd4fa..233e5e4eb 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -73,6 +73,8 @@ private: TEST_CASE(doublefree6); // #7685 TEST_CASE(doublefree7); TEST_CASE(doublefree8); + TEST_CASE(doublefree9); + // exit TEST_CASE(exit1); @@ -944,6 +946,17 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Memory pointed to by 'i' is freed twice.\n", errout.str()); } + void doublefree9() { + check("struct foo {\n" + " int* get(int) { return new int(); }\n" + "};\n" + "void f(foo* b) {\n" + " std::unique_ptr x(b->get(0));\n" + " std::unique_ptr y(b->get(1));\n" + "}\n", true); + ASSERT_EQUALS("", errout.str()); + } + void exit1() { check("void f() {\n" " char *p = malloc(10);\n"