CheckMemoryLeak: fixed bug that caused false positives
This commit is contained in:
parent
bb5276024b
commit
90c2822031
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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, "" );
|
||||
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
|
Loading…
Reference in New Issue