Fix #12321 FP doubleFree within lambda (#5844)

This commit is contained in:
chrchr-github 2024-01-05 22:20:21 +01:00 committed by GitHub
parent 44ed53319e
commit fde7ea6d17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -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();
}
}

View File

@ -986,6 +986,20 @@ private:
" FOREACH(callables, ());\n"
"}\n");
ASSERT_EQUALS("[test.c:2]: (information) --check-library: Function FOREACH() should have <noreturn> 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