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"