Fixed #8100 (False positive when method/function defines lambda with pointer return value)

This commit is contained in:
Daniel Marjamäki 2018-11-12 11:28:26 +01:00
parent f096d7f474
commit 3d629944da
2 changed files with 12 additions and 0 deletions

View File

@ -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)

View File

@ -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"