Fixed #8848 (False positive memory leak if locally defined type returns a new pointer)
This commit is contained in:
parent
0edf0b5628
commit
80d7df01cd
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue