memory leaks: better handling of 'loop { dealloc ; alloc ; }'

This commit is contained in:
Daniel Marjamäki 2010-08-02 22:14:51 +02:00
parent ae0252dc91
commit ff9d3d0965
2 changed files with 17 additions and 1 deletions

View File

@ -1830,6 +1830,20 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false;
}
// Reduce "loop|while1 { dealloc ; alloc ; }"
if (Token::Match(tok2, "loop|while1 { dealloc ; alloc ; }"))
{
// delete "loop|while1"
tok2->deleteThis();
// delete "{"
tok2->deleteThis();
// delete "}"
Token::eraseTokens(tok2->tokAt(3), tok2->tokAt(5));
done = false;
}
// Delete if block in "alloc ; if(!var) return ;"
if (Token::Match(tok2, "alloc ; if(!var) return ;"))
{

View File

@ -699,6 +699,8 @@ private:
ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; while1 { if { dealloc ; return ; } if { break ; } }"));
ASSERT_EQUALS(";", simplifycode("; do { dealloc ; alloc ; } while(var) ;"));
ASSERT_EQUALS("dealloc ; alloc ;", simplifycode("loop { dealloc ; alloc ; }"));
ASSERT_EQUALS("dealloc ; alloc ;", simplifycode("while1 { dealloc ; alloc ; }"));
// scope..
// current result - ok
@ -709,7 +711,7 @@ private:
// callfunc..
ASSERT_EQUALS("; callfunc ;", simplifycode(";callfunc;"));
ASSERT_EQUALS(";", simplifycode(";callfunc;;"));
ASSERT_EQUALS("while1 { dealloc ; alloc ; } return ; }", simplifycode("while1 { dealloc ; alloc ; } callfunc ; return ; }"));
ASSERT_EQUALS("dealloc ; alloc ; return ; }", simplifycode("while1 { dealloc ; alloc ; } callfunc ; return ; }"));
// exit..
ASSERT_EQUALS("; exit ;", simplifycode("; alloc; exit;"));