CheckMemoryLeak: Handle one more test case (return pointer)

This commit is contained in:
Daniel Marjamäki 2008-08-13 19:08:24 +00:00
parent 0394aedd52
commit 46be988e9a
2 changed files with 21 additions and 2 deletions

View File

@ -385,7 +385,7 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
}
// Return without deallocating the memory..
if ( Alloc != No && alloc_indentlevel >= 0 && dealloc_indentlevel <= 0 && Match(tok, "return") )
if ( Alloc != No && (indentlevel==0 || (alloc_indentlevel >= 0 && dealloc_indentlevel <= 0)) && Match(tok, "return") )
{
bool retvar = false;
for ( const TOKEN *tok2 = tok->next; tok2; tok2 = tok2->next )
@ -435,8 +435,15 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
}
}
if ( indentlevel <= alloc_indentlevel )
if ( indentlevel == 0 )
return;
if ( indentlevel <= alloc_indentlevel )
{
Alloc = No;
alloc_indentlevel = -1;
dealloc_indentlevel = -1;
}
}
}
}

View File

@ -595,6 +595,18 @@ static void memleak_in_function()
check( CheckMemoryLeak, __LINE__, code, "[test.cpp:8]: Memory leak: s\n" );
code = "static char *f()\n"
"{\n"
" char *s;\n"
" if ( abc )\n"
" {\n"
" s = new char[10];\n"
" }\n"
" return s;\n"
"}\n";
check( CheckMemoryLeak, __LINE__, code, "" );