Refactoring CheckMemoryLeak to detect more leaks

This commit is contained in:
Daniel Marjamäki 2008-04-08 07:03:32 +00:00
parent 137a4c6309
commit bee1c1fb8d
2 changed files with 25 additions and 1 deletions

View File

@ -169,7 +169,10 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
} }
// Used.. // Used..
if ( Match( tok, "[=,(] %var1%", varnames ) ) // list.push_back( var1 );
// listtail->next = var1;
// foo( var1 );
if ( Match( tok, "[=,(] %var1% [,);]", varnames ) )
return; return;
if ( Match( tok, "return %var1%", varnames ) ) if ( Match( tok, "return %var1%", varnames ) )
return; return;

View File

@ -564,6 +564,27 @@ static void memleak_in_function()
"}\n"; "}\n";
check( CheckMemoryLeak, __LINE__, test10, "[test.cpp:3]: Memory leak: obj_list\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" );
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------