From ba4ea7c399cbc359aabcf72f088f2df08b104e41 Mon Sep 17 00:00:00 2001 From: chrchr Date: Fri, 5 Jan 2024 18:36:51 +0100 Subject: [PATCH 1/2] Fix #12321 FP doubleFree within lambda --- lib/checkleakautovar.cpp | 3 +++ test/testleakautovar.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 14b9b47eb8e..bee4b95e291 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(); do { checkTokenInsideExpression(arg, varInfo, /*inFuncCall*/ isLeakIgnore); + + if (isLambdaCaptureList(arg)) + break; arg = arg->next(); } while ((nextArg && arg != nextArg) || (!nextArg && arg != tokOpeningPar->link())); } diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 280c428345c..b08f668afce 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -981,6 +981,20 @@ class TestLeakAutoVar : public TestFixture { ASSERT_EQUALS("[test.c:4]: (error) Dereferencing 'p' after it is deallocated / released\n" "[test.c:7] -> [test.c:8]: (error) Returning/dereferencing 'p' after it is deallocated / released\n", errout.str()); + + 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", "test.cpp"); + ASSERT_EQUALS("", errout.str()); } void doublefree1() { // #3895 From 4a8a468b92e7b820380110094c222834a55a7c86 Mon Sep 17 00:00:00 2001 From: chrchr Date: Fri, 5 Jan 2024 19:03:11 +0100 Subject: [PATCH 2/2] clang-tidy --- test/testleakautovar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index ce2ffc1e859..c6815db4bab 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -998,7 +998,7 @@ class TestLeakAutoVar : public TestFixture { " free(p);\n" " }, 1);\n" " return 0;\n" - "}\n", "test.cpp"); + "}\n", /*cpp*/ true); ASSERT_EQUALS("", errout.str()); }