CheckMemoryLeak: fixed bug that caused false positives

This commit is contained in:
Daniel Marjamäki 2008-04-12 11:33:48 +00:00
parent bb5276024b
commit 90c2822031
2 changed files with 19 additions and 0 deletions

View File

@ -174,11 +174,21 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
// foo( var1 );
if ( Match( tok, "[=,(] %var1% [,);]", varnames ) )
return;
// Return the memory..
if ( Match( tok, "return %var1%", varnames ) )
return;
// Return without deallocating the memory..
if ( Alloc != No && alloc_indentlevel >= 0 && Match(tok, "return") )
{
for ( const TOKEN *tok2 = tok->next; tok2; tok2 = tok2->next )
{
if ( Match( tok2, "%var1%", varnames ) )
return;
if ( tok2->str[0] == ';' )
break;
}
MemoryLeak( tok, varname );
return;
}

View File

@ -608,6 +608,15 @@ static void memleak_in_function()
check( CheckMemoryLeak, __LINE__, test14, "[test.cpp:9]: Memory leak: f.str\n" );
*/
const char test15[] = "static char *f()\n"
"{\n"
" char *s = new char[100];\n"
" return (char *)s;\n"
"}\n";
check( CheckMemoryLeak, __LINE__, test15, "" );
}
//---------------------------------------------------------------------------