CheckMemoryLeak: Removed false positives

This commit is contained in:
Daniel Marjamäki 2008-05-04 10:15:39 +00:00
parent a4486fb883
commit 4094f6bc6e
2 changed files with 21 additions and 2 deletions

View File

@ -210,6 +210,11 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
if ( Match( tok, "[=,(] ( %type% %type% * ) %var1% [,);]", varnames ) )
return;
// Used. Todo: check if "p" is the first member in the struct.
// p = &var1->p;
if ( Match( tok, "= & %var1% . %var% ;", varnames ) )
return;
// Linux lists..
if ( Match( tok, "%var% ( & %var1% .", varnames ) )
{

View File

@ -637,10 +637,10 @@ static void memleak_in_function()
" char *str = strdup(\"hello\");\n"
" char *str2 = (char *)str;\n"
" free(str2);\n"
"}\n";
"}\n";
check( CheckMemoryLeak, __LINE__, test17, "" );
const char test18[] = "static void f()\n"
"{\n"
" char *str;\n"
@ -650,6 +650,20 @@ static void memleak_in_function()
"}\n";
check( CheckMemoryLeak, __LINE__, test18, "" );
const char test19[] = "struct abc\n"
"{\n"
" int a;\n"
" int b;\n"
" int c;\n"
"}\n"
"\n"
"static void f()\n"
"{\n"
" struct abc *abc1 = new abc;\n"
" p = &abc1->a;\n"
"}\n";
check( CheckMemoryLeak, __LINE__, test19, "" );
}
//---------------------------------------------------------------------------