Fixed #2235 (false Resource leak)
This commit is contained in:
parent
2ed14431fe
commit
03a92582ca
|
@ -1716,6 +1716,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
|||
done = false;
|
||||
}
|
||||
|
||||
// Reduce "if continue ; if continue ;" => "if continue ;"
|
||||
else if (Token::Match(tok2->next(), "if continue ; if continue ;"))
|
||||
{
|
||||
Token::eraseTokens(tok2, tok2->tokAt(4));
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Reduce "if return ; alloc ;" => "alloc ;"
|
||||
else if (Token::Match(tok2, "[;{}] if return ; alloc|return ;"))
|
||||
{
|
||||
|
@ -1759,6 +1766,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
|
|||
done = false;
|
||||
}
|
||||
|
||||
// Remove "else" after "if continue|break|return"
|
||||
else if (Token::Match(tok2->next(), "if continue|break|return ; else"))
|
||||
{
|
||||
tok2->tokAt(4)->deleteThis();
|
||||
done = false;
|
||||
}
|
||||
|
||||
// Delete "if { dealloc|assign|use ; return ; }"
|
||||
else if (Token::Match(tok2, "[;{}] if { dealloc|assign|use ; return ; }"))
|
||||
{
|
||||
|
@ -2273,6 +2287,8 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string
|
|||
tok2->str("use");
|
||||
else if (tok2->str() == "use_")
|
||||
tok2->str(";");
|
||||
else if (Token::simpleMatch(tok2, "loop use_ {"))
|
||||
tok2->deleteNext();
|
||||
else if (tok2->str() == "::use") // Some kind of member function usage. Not analyzed very well.
|
||||
tok2->str("use");
|
||||
else if (tok2->str() == "recursive")
|
||||
|
|
|
@ -686,9 +686,9 @@ private:
|
|||
ASSERT_EQUALS("; alloc ;", simplifycode("; if { alloc; } else { return; }"));
|
||||
ASSERT_EQUALS("; alloc ; dealloc ;", simplifycode("; alloc ; if(!var) { alloc ; } dealloc ;"));
|
||||
ASSERT_EQUALS("; use ;", simplifycode("; if(var) use ;"));
|
||||
ASSERT_EQUALS("; break ;", simplifycode("; if break ; else break ;"));
|
||||
ASSERT_EQUALS(";", simplifycode("; if break ; else break ;"));
|
||||
ASSERT_EQUALS("; alloc ; if return ;", simplifycode("; alloc ; loop { if return ; if continue ; }"));
|
||||
ASSERT_EQUALS("; alloc ; if return ;", simplifycode("; alloc ; loop { if continue ; else return ; }"));
|
||||
ASSERT_EQUALS("; alloc ; loop return ;", simplifycode("; alloc ; loop { if continue ; else return ; }"));
|
||||
|
||||
ASSERT_EQUALS("; alloc ; if dealloc ;", simplifycode("; alloc ; if(!var) { return ; } if { dealloc ; }"));
|
||||
ASSERT_EQUALS("; if alloc ; else assign ; return use ;", simplifycode("; callfunc ; if callfunc { alloc ; } else { assign ; } return use ;"));
|
||||
|
@ -740,6 +740,9 @@ private:
|
|||
ASSERT_EQUALS("dealloc ; alloc ;", simplifycode("while1 { dealloc ; alloc ; }"));
|
||||
ASSERT_EQUALS("use ; }", simplifycode("loop { use ; callfunc ; } }"));
|
||||
|
||||
ASSERT_EQUALS(";", simplifycode("; loop { if { continue ; } else { if continue ; } }"));
|
||||
ASSERT_EQUALS(";", simplifycode("; loop { { if continue ; if continue ; } }"));
|
||||
|
||||
// scope..
|
||||
// current result - ok
|
||||
ASSERT_EQUALS("; assign ; dealloc ; if alloc ; }", simplifycode("; assign ; { dealloc ; if alloc ; } }"));
|
||||
|
|
Loading…
Reference in New Issue