Minor updates. Added todo. Refactoring

This commit is contained in:
Daniel Marjamäki 2008-04-12 12:07:35 +00:00
parent 4805f48a4f
commit 53f078fc1d
3 changed files with 13 additions and 4 deletions

View File

@ -464,9 +464,10 @@ void CheckMemset()
// Locate all 'memset' tokens.. // Locate all 'memset' tokens..
for (const TOKEN *tok = tokens; tok; tok = tok->next) for (const TOKEN *tok = tokens; tok; tok = tok->next)
{ {
if (strcmp(tok->str,"memset")!=0) if (!Match(tok,"memset") && !Match(tok,"memcpy") && !Match(tok,"memmove"))
continue; continue;
// Todo: Handle memcpy and memmove
const char *type = NULL; const char *type = NULL;
if (Match(tok, "memset ( %var% , %num% , sizeof ( %type% ) )")) if (Match(tok, "memset ( %var% , %num% , sizeof ( %type% ) )"))
type = getstr(tok, 8); type = getstr(tok, 8);

View File

@ -175,6 +175,15 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
if ( Match( tok, "[=,(] %var1% [,);]", varnames ) ) if ( Match( tok, "[=,(] %var1% [,);]", varnames ) )
return; return;
// continue/break loop..
if (Alloc != No &&
alloc_indentlevel == indentlevel &&
(Match(tok,"continue") || Match(tok,"break")))
{
MemoryLeak( tok, varname );
return;
}
// Return without deallocating the memory.. // Return without deallocating the memory..
if ( Alloc != No && alloc_indentlevel >= 0 && Match(tok, "return") ) if ( Alloc != No && alloc_indentlevel >= 0 && Match(tok, "return") )
{ {

View File

@ -472,7 +472,6 @@ static void memleak_in_function()
check( CheckMemoryLeak, __LINE__, test3, "" ); check( CheckMemoryLeak, __LINE__, test3, "" );
/* TODO
const char test4[] = "void f()\n" const char test4[] = "void f()\n"
"{\n" "{\n"
" for (int i = 0; i < j; i++)\n" " for (int i = 0; i < j; i++)\n"
@ -483,8 +482,8 @@ static void memleak_in_function()
" free(str);\n" " free(str);\n"
" }\n" " }\n"
"}\n"; "}\n";
check( CheckMemoryLeak, __LINE__, test4, "[test.cpp:7]: Memory leak:str\n" ); check( CheckMemoryLeak, __LINE__, test4, "[test.cpp:7]: Memory leak: str\n" );
*/