CheckMemoryLeak: Made a test case work

This commit is contained in:
Daniel Marjamäki 2008-08-17 17:17:17 +00:00
parent 76fdae51d9
commit daf0563b07
2 changed files with 17 additions and 5 deletions

View File

@ -711,16 +711,28 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
done = false; done = false;
} }
// Delete "alloc ; if(!var) return ;" // Delete if block in "alloc ; if(!var) return ;"
if ( Match(tok2->next, "alloc ; if(!var) return ;") ) if ( Match(tok2, "alloc ; if(!var) return ;") )
{ {
erase(tok2, gettok(tok2,6)); erase(tok2, gettok(tok2,4));
done = false;
}
// Delete second use in "use ; use;"
while (Match(tok2, "use ; use ;"))
{
erase(tok2, gettok(tok2,3));
done = false; done = false;
} }
} }
} }
if ( findmatch(tok,"alloc ; return ;") ) if ( findmatch(tok, "alloc ; if continue ;") )
{
MemoryLeak(gettok(findmatch(tok, "alloc ; if continue ;"), 4), varname);
}
else if ( findmatch(tok, "alloc ; return ;") )
{ {
MemoryLeak(gettok(findmatch(tok,"alloc ; return ;"),2), varname); MemoryLeak(gettok(findmatch(tok,"alloc ; return ;"),2), varname);
} }

View File

@ -676,7 +676,7 @@ static void memleak_in_function()
" free(str);\n" " free(str);\n"
" }\n" " }\n"
"}\n"; "}\n";
check( CheckMemoryLeak, __LINE__, code, "[test.cpp:7]: Memory leak: str\n" ); check_( CheckMemoryLeak, __LINE__, code, "[test.cpp:7]: Memory leak: str\n" );