Fixed #715 (False positive: Resource leak when exit() after if loop)

This commit is contained in:
Daniel Marjamäki 2009-09-22 18:09:29 +02:00
parent faac5bccd6
commit ad92aa4c20
2 changed files with 10 additions and 1 deletions

View File

@ -1352,13 +1352,21 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
done = false;
}
// Reduce "alloc|dealloc|use ; exit ;" => "; exit ;"
// Reduce "alloc|dealloc|use|callfunc ; exit ;" => "; exit ;"
if (Token::Match(tok2, "alloc|dealloc|use|callfunc ; exit ;"))
{
tok2->deleteThis();
done = false;
}
// Reduce "if loop ; exit ;" => "; exit ;"
if (Token::Match(tok2, "if loop ; exit ;"))
{
tok2->deleteThis();
tok2->deleteThis();
done = false;
}
// Reduce "alloc|dealloc|use ; if(var) exit ;"
if (Token::Match(tok2, "alloc|dealloc|use ; if(var) exit ;"))
{

View File

@ -490,6 +490,7 @@ private:
// exit..
ASSERT_EQUALS("; exit ;", simplifycode("; alloc; exit;"));
ASSERT_EQUALS("; exit ;", simplifycode("; alloc; if { loop ; } dealloc; exit;"));
ASSERT_EQUALS(";", simplifycode("; if { alloc; exit; }"));
ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; if { use; exit; }"));
ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; if(!var) { exit; }"));