CheckMemoryLeak: Added testcase and made it work (assume that

foo.add(p) deallocates p. Todo to trace into foo.add)
This commit is contained in:
Daniel Marjamäki 2008-08-15 17:16:17 +00:00
parent 6b12d31f5f
commit 0ce33fe1da
2 changed files with 29 additions and 1 deletions

View File

@ -168,6 +168,26 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
dealloc_indentlevel = -1;
}
if ( Alloc != No && Match(tok, ". %var% (") )
{
bool isused = false;
while (tok && !Match(tok, "[;{]"))
{
if ( Match(tok, "[(,] %var1% [,)]", varnames) )
isused = true;
tok = tok->next;
}
// Don't know what happens, assume that it's deallocated.
if ( isused )
{
if ( indentlevel == 0 )
return;
dealloc_indentlevel = indentlevel;
}
}
// Check subfunction...
if (Alloc != No && Match(tok,"[{};] %var% ("))
{

View File

@ -653,7 +653,7 @@ static void memleak_in_function()
////////////////////////////////////////////////
// switch
////////////////////////////////////////////////
code = "void f()\n"
"{\n"
" char *str = new char[10];\n"
@ -817,6 +817,14 @@ static void memleak_in_function()
"}\n";
check( CheckMemoryLeak, __LINE__, code, "" );
code = "static void f()\n"
"{\n"
" char *p = new char[100];\n"
" foo.add(p);\n"
"}\n";
check( CheckMemoryLeak, __LINE__, code, "" );
}
//---------------------------------------------------------------------------