Refactoring CheckMemoryLeak to detect more leaks
This commit is contained in:
parent
137a4c6309
commit
bee1c1fb8d
|
@ -169,7 +169,10 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
}
|
||||
|
||||
// Used..
|
||||
if ( Match( tok, "[=,(] %var1%", varnames ) )
|
||||
// list.push_back( var1 );
|
||||
// listtail->next = var1;
|
||||
// foo( var1 );
|
||||
if ( Match( tok, "[=,(] %var1% [,);]", varnames ) )
|
||||
return;
|
||||
if ( Match( tok, "return %var1%", varnames ) )
|
||||
return;
|
||||
|
|
21
tests.cpp
21
tests.cpp
|
@ -564,6 +564,27 @@ static void memleak_in_function()
|
|||
"}\n";
|
||||
check( CheckMemoryLeak, __LINE__, test10, "[test.cpp:3]: Memory leak: obj_list\n" );
|
||||
|
||||
|
||||
|
||||
const char test11[] = "static char *f()\n"
|
||||
"{\n"
|
||||
" char *s = new char[100];\n"
|
||||
" return s;\n"
|
||||
"}\n";
|
||||
check( CheckMemoryLeak, __LINE__, test11, "" );
|
||||
|
||||
|
||||
|
||||
|
||||
const char test12[] = "static char *f()\n"
|
||||
"{\n"
|
||||
" Fred *fred = new Fred;\n"
|
||||
" free( fred->Name );\n"
|
||||
"}\n";
|
||||
check( CheckMemoryLeak, __LINE__, test12, "[test.cpp:3]: Memory leak: fred\n" );
|
||||
|
||||
|
||||
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
|
Loading…
Reference in New Issue