memory leaks: better handling of 'loop { dealloc ; alloc ; }'
This commit is contained in:
parent
ae0252dc91
commit
ff9d3d0965
|
@ -1830,6 +1830,20 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
||||||
done = false;
|
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 ;"
|
// Delete if block in "alloc ; if(!var) return ;"
|
||||||
if (Token::Match(tok2, "alloc ; if(!var) return ;"))
|
if (Token::Match(tok2, "alloc ; if(!var) return ;"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -699,6 +699,8 @@ private:
|
||||||
ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; while1 { if { dealloc ; return ; } if { break ; } }"));
|
ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; while1 { if { dealloc ; return ; } if { break ; } }"));
|
||||||
|
|
||||||
ASSERT_EQUALS(";", simplifycode("; do { dealloc ; alloc ; } while(var) ;"));
|
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..
|
// scope..
|
||||||
// current result - ok
|
// current result - ok
|
||||||
|
@ -709,7 +711,7 @@ private:
|
||||||
// callfunc..
|
// callfunc..
|
||||||
ASSERT_EQUALS("; callfunc ;", simplifycode(";callfunc;"));
|
ASSERT_EQUALS("; callfunc ;", simplifycode(";callfunc;"));
|
||||||
ASSERT_EQUALS(";", 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..
|
// exit..
|
||||||
ASSERT_EQUALS("; exit ;", simplifycode("; alloc; exit;"));
|
ASSERT_EQUALS("; exit ;", simplifycode("; alloc; exit;"));
|
||||||
|
|
Loading…
Reference in New Issue