Fixed #8848 (False positive memory leak if locally defined type returns a new pointer)

This commit is contained in:
Daniel Marjamäki 2019-04-22 17:37:41 +02:00
parent 0edf0b5628
commit 80d7df01cd
2 changed files with 11 additions and 0 deletions

View File

@ -363,6 +363,8 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* f
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() == "{" && !tok2->scope()->isExecutable())
tok2 = tok2->link();
if (tok2->str() == "return") {
const AllocType allocType = getAllocationType(tok2->next(), 0, callstack);
if (allocType != No)

View File

@ -1928,6 +1928,15 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
check("void *f() {\n" // #8848
" struct S { void *alloc() { 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"