Fixed #2235 (false Resource leak)

This commit is contained in:
Daniel Marjamäki 2010-11-27 11:09:42 +01:00
parent 2ed14431fe
commit 03a92582ca
2 changed files with 21 additions and 2 deletions

View File

@ -1716,6 +1716,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false; 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 ;" // Reduce "if return ; alloc ;" => "alloc ;"
else if (Token::Match(tok2, "[;{}] if return ; alloc|return ;")) else if (Token::Match(tok2, "[;{}] if return ; alloc|return ;"))
{ {
@ -1759,6 +1766,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok)
done = false; 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 ; }" // Delete "if { dealloc|assign|use ; return ; }"
else if (Token::Match(tok2, "[;{}] 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"); tok2->str("use");
else if (tok2->str() == "use_") else if (tok2->str() == "use_")
tok2->str(";"); 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. else if (tok2->str() == "::use") // Some kind of member function usage. Not analyzed very well.
tok2->str("use"); tok2->str("use");
else if (tok2->str() == "recursive") else if (tok2->str() == "recursive")

View File

@ -686,9 +686,9 @@ private:
ASSERT_EQUALS("; alloc ;", simplifycode("; if { alloc; } else { return; }")); ASSERT_EQUALS("; alloc ;", simplifycode("; if { alloc; } else { return; }"));
ASSERT_EQUALS("; alloc ; dealloc ;", simplifycode("; alloc ; if(!var) { alloc ; } dealloc ;")); ASSERT_EQUALS("; alloc ; dealloc ;", simplifycode("; alloc ; if(!var) { alloc ; } dealloc ;"));
ASSERT_EQUALS("; use ;", simplifycode("; if(var) use ;")); 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 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("; 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 ;")); 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("dealloc ; alloc ;", simplifycode("while1 { dealloc ; alloc ; }"));
ASSERT_EQUALS("use ; }", simplifycode("loop { use ; callfunc ; } }")); 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.. // scope..
// current result - ok // current result - ok
ASSERT_EQUALS("; assign ; dealloc ; if alloc ; }", simplifycode("; assign ; { dealloc ; if alloc ; } }")); ASSERT_EQUALS("; assign ; dealloc ; if alloc ; }", simplifycode("; assign ; { dealloc ; if alloc ; } }"));