Skip to content

Commit fde7ea6

Browse files
Fix #12321 FP doubleFree within lambda (#5844)
1 parent 44ed533 commit fde7ea6

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/checkleakautovar.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,9 @@ void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpenin
10481048
const Token* const nextArg = funcArg->nextArgument();
10491049
while (arg && ((nextArg && arg != nextArg) || (!nextArg && arg != tokOpeningPar->link()))) {
10501050
checkTokenInsideExpression(arg, varInfo, /*inFuncCall*/ isLeakIgnore);
1051+
1052+
if (isLambdaCaptureList(arg))
1053+
break;
10511054
arg = arg->next();
10521055
}
10531056
}

test/testleakautovar.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,20 @@ class TestLeakAutoVar : public TestFixture {
986986
" FOREACH(callables, ());\n"
987987
"}\n");
988988
ASSERT_EQUALS("[test.c:2]: (information) --check-library: Function FOREACH() should have <noreturn> configuration\n", errout.str()); // don't crash
989+
990+
check("int f() {\n" // #12321
991+
" std::invoke([](int i) {\n"
992+
" int* p = (int*)malloc(4);\n"
993+
" *p = 0;\n"
994+
" if (i) {\n"
995+
" free(p);\n"
996+
" return;\n"
997+
" }\n"
998+
" free(p);\n"
999+
" }, 1);\n"
1000+
" return 0;\n"
1001+
"}\n", /*cpp*/ true);
1002+
ASSERT_EQUALS("", errout.str());
9891003
}
9901004

9911005
void doublefree1() { // #3895

0 commit comments

Comments
 (0)