diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index a5731e157..bba098520 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -353,6 +353,8 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* f // Get return pointer.. unsigned int varid = 0; for (const Token *tok2 = func->functionScope->bodyStart; tok2 != func->functionScope->bodyEnd; tok2 = tok2->next()) { + if (const Token *endOfLambda = findLambdaEndToken(tok2)) + tok2 = endOfLambda; if (tok2->str() == "return") { const AllocType allocType = getAllocationType(tok2->next(), 0, callstack); if (allocType != No) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 73b2dcaac..68c59c676 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -5869,6 +5869,16 @@ private: "}"); ASSERT_EQUALS("[test.cpp:7]: (error) Return value of allocation function 'f' is not stored.\n", errout.str()); + check("void f()\n" // #8100 + "{\n" + " auto lambda = [](){return malloc(10);};\n" + "}\n" + "void x()\n" + "{\n" + " f();\n" + "}"); + ASSERT_EQUALS("", errout.str()); + check("void x()\n" "{\n" " if(!malloc(5)) fail();\n"