Skip to content

Commit

Permalink
Fix #12321 FP doubleFree within lambda (danmar#5844)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Jan 5, 2024
1 parent 44ed533 commit fde7ea6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
14 changes: 14 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,20 @@ class TestLeakAutoVar : public TestFixture {
" 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
Expand Down

0 comments on commit fde7ea6

Please sign in to comment.