diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 6b02301af..d6d86a6f1 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -1048,6 +1048,9 @@ void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpenin const Token* const nextArg = funcArg->nextArgument(); while (arg && ((nextArg && arg != nextArg) || (!nextArg && arg != tokOpeningPar->link()))) { checkTokenInsideExpression(arg, varInfo, /*inFuncCall*/ isLeakIgnore); + + if (isLambdaCaptureList(arg)) + break; arg = arg->next(); } } diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index e6de5e6e6..c6815db4b 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -986,6 +986,20 @@ private: " FOREACH(callables, ());\n" "}\n"); ASSERT_EQUALS("[test.c:2]: (information) --check-library: Function FOREACH() should have configuration\n", errout.str()); // don't crash + + check("int f() {\n" // #12321 + " std::invoke([](int i) {\n" + " int* p = (int*)malloc(4);\n" + " *p = 0;\n" + " if (i) {\n" + " free(p);\n" + " return;\n" + " }\n" + " free(p);\n" + " }, 1);\n" + " return 0;\n" + "}\n", /*cpp*/ true); + ASSERT_EQUALS("", errout.str()); } void doublefree1() { // #3895