CheckMemoryLeak: Handle one more test case (return pointer)
This commit is contained in:
parent
0394aedd52
commit
46be988e9a
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
tests.cpp
12
tests.cpp
|
@ -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, "" );
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue