Fixed #728 (False positive, resource leak, when released in a loop)
This commit is contained in:
parent
342e71803f
commit
a61abcbbc8
|
@ -863,6 +863,12 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
||||||
// Loops..
|
// Loops..
|
||||||
else if ((tok->str() == "for") || (tok->str() == "while"))
|
else if ((tok->str() == "for") || (tok->str() == "while"))
|
||||||
{
|
{
|
||||||
|
if (Token::simpleMatch(tok, "while ( true )"))
|
||||||
|
{
|
||||||
|
addtoken("while1");
|
||||||
|
tok = tok->next()->link();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
addtoken("loop");
|
addtoken("loop");
|
||||||
isloop = true;
|
isloop = true;
|
||||||
}
|
}
|
||||||
|
@ -1320,6 +1326,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all)
|
||||||
done = false;
|
done = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reduce "while1 ;" => "use ;"
|
||||||
|
if (Token::simpleMatch(tok2, "while1 ;"))
|
||||||
|
{
|
||||||
|
tok2->str("use");
|
||||||
|
done = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Delete if block: "alloc; if return use ;"
|
// Delete if block: "alloc; if return use ;"
|
||||||
if (Token::Match(tok2, "alloc ; if return use ; !!else"))
|
if (Token::Match(tok2, "alloc ; if return use ; !!else"))
|
||||||
{
|
{
|
||||||
|
|
|
@ -350,6 +350,7 @@ private:
|
||||||
ASSERT_EQUALS(";;loop{}", getcode("char *s; for (a;b;c) { }", "s"));
|
ASSERT_EQUALS(";;loop{}", getcode("char *s; for (a;b;c) { }", "s"));
|
||||||
ASSERT_EQUALS(";;loop{alloc;}", getcode("char *s; for (a;b;c) { s=malloc(10); }", "s"));
|
ASSERT_EQUALS(";;loop{alloc;}", getcode("char *s; for (a;b;c) { s=malloc(10); }", "s"));
|
||||||
ASSERT_EQUALS(";;do{}loop;", getcode("char *s; do { } while (a);", "s"));
|
ASSERT_EQUALS(";;do{}loop;", getcode("char *s; do { } while (a);", "s"));
|
||||||
|
ASSERT_EQUALS(";;while1{}", getcode("char *s; while(true) { }", "s"));
|
||||||
|
|
||||||
// asprintf..
|
// asprintf..
|
||||||
ASSERT_EQUALS(";;alloc;", getcode("char *s; asprintf(&s, \"xyz\");", "s"));
|
ASSERT_EQUALS(";;alloc;", getcode("char *s; asprintf(&s, \"xyz\");", "s"));
|
||||||
|
@ -485,6 +486,8 @@ private:
|
||||||
ASSERT_EQUALS("; alloc ; alloc ;", simplifycode("; alloc ; do { alloc ; } loop ;"));
|
ASSERT_EQUALS("; alloc ; alloc ;", simplifycode("; alloc ; do { alloc ; } loop ;"));
|
||||||
ASSERT_EQUALS("; exit ;", simplifycode("; alloc ; do { } loop ; exit ;"));
|
ASSERT_EQUALS("; exit ;", simplifycode("; alloc ; do { } loop ; exit ;"));
|
||||||
|
|
||||||
|
ASSERT_EQUALS("; alloc ; use ;", simplifycode("; alloc ; while1 { if { dealloc ; return ; } }"));
|
||||||
|
|
||||||
// callfunc..
|
// callfunc..
|
||||||
ASSERT_EQUALS("; callfunc ;\n;", simplifycode(";callfunc;"));
|
ASSERT_EQUALS("; callfunc ;\n;", simplifycode(";callfunc;"));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue