Fixed #2900 (found memory leak in kernel p54usb and a false positive reported)

This commit is contained in:
Daniel Marjamäki 2011-08-02 09:04:13 +02:00
parent 0c2f2e1c38
commit 5fc2a55bac
2 changed files with 7 additions and 2 deletions

View File

@ -1915,8 +1915,9 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false;
}
// Remove "if { dealloc ; callfunc ; } !!else"
else if (Token::Match(tok2->next(), "if { dealloc|assign ; callfunc ; } !!else"))
// Remove "if { dealloc ; callfunc ; } !!else|return"
else if (Token::Match(tok2->next(), "if { dealloc|assign ; callfunc ; }") &&
!Token::Match(tok2->tokAt(8), "else|return"))
{
Token::eraseTokens(tok2, tok2->tokAt(8));
done = false;

View File

@ -738,6 +738,10 @@ private:
ASSERT_EQUALS("dealloc ; alloc ; return ; }", simplifycode("while1 { dealloc ; alloc ; } callfunc ; return ; }"));
ASSERT_EQUALS("; }", simplifycode("loop callfunc ; }"));
// #2900 - don't report false positive
ASSERT_EQUALS("; alloc ; if { if { dealloc ; callfunc ; } return ; } dealloc ; }",
simplifycode("; alloc ; if { if { dealloc ; callfunc ; } return ; } dealloc ; }"));
// exit..
ASSERT_EQUALS("; exit ;", simplifycode("; alloc; exit;"));
ASSERT_EQUALS("; exit ;", simplifycode("; alloc; if { loop ; } dealloc; exit;"));