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:
parent
6b12d31f5f
commit
0ce33fe1da
|
@ -168,6 +168,26 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
||||||
dealloc_indentlevel = -1;
|
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...
|
// Check subfunction...
|
||||||
if (Alloc != No && Match(tok,"[{};] %var% ("))
|
if (Alloc != No && Match(tok,"[{};] %var% ("))
|
||||||
{
|
{
|
||||||
|
|
|
@ -817,6 +817,14 @@ static void memleak_in_function()
|
||||||
"}\n";
|
"}\n";
|
||||||
check( CheckMemoryLeak, __LINE__, code, "" );
|
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, "" );
|
||||||
|
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue