From fde7ea6d17840a8e4bfa9ceac186472bf77f8086 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 5 Jan 2024 22:20:21 +0100 Subject: [PATCH] Fix #12321 FP doubleFree within lambda (#5844) --- lib/checkleakautovar.cpp | 3 +++ test/testleakautovar.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+) 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