Fix ticket #352 (Memory leaks: Missed memory leak when "--all" is not given)

http://apps.sourceforge.net/trac/cppcheck/ticket/352
Detect memory leaks without --all when there is "alloc ; assign callfunc ;
This commit is contained in:
Reijo Tomperi 2009-06-03 23:20:33 +03:00
parent 3428584925
commit 1bb7b01a06
2 changed files with 9 additions and 1 deletions

View File

@ -1333,7 +1333,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope(const Token *Tok1, const c
MemoryLeak(result->tokAt(3), varname, alloctype, all);
}
else if ((result = Token::findmatch(tok, "alloc ; alloc|assign|return ;")) != NULL)
else if ((result = Token::findmatch(tok, "alloc ; alloc|assign|return callfunc| ;")) != NULL)
{
MemoryLeak(result->tokAt(2), varname, alloctype, all);
}

View File

@ -1993,6 +1993,14 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:9]: (error) Memory leak: p\n", errout.str());
check("void foo()\n"
"{\n"
" int *p = new int[100];\n"
" p = g();\n"
" delete [] p;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: p\n", errout.str());
}
void unknownFunction3()