Fixed #2261 (False positive: memory leak)

This commit is contained in:
Daniel Marjamäki 2010-11-30 19:36:04 +01:00
parent 6761765a70
commit 0081800a20
2 changed files with 11 additions and 0 deletions

View File

@ -1518,6 +1518,16 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
} }
} }
for (Token *tok1 = rethead; tok1; tok1 = tok1->next())
{
if (Token::simpleMatch(tok1, "callfunc alloc ;"))
{
tok1->deleteThis();
tok1->insertToken("use");
tok1->insertToken(";");
}
}
return rethead; return rethead;
} }

View File

@ -535,6 +535,7 @@ private:
ASSERT_EQUALS(";;;use;", getcode("char *p; const char *q; q = p;", "p")); ASSERT_EQUALS(";;;use;", getcode("char *p; const char *q; q = p;", "p"));
ASSERT_EQUALS(";;use;;", getcode("char *s; x = {1,s};", "s")); ASSERT_EQUALS(";;use;;", getcode("char *s; x = {1,s};", "s"));
ASSERT_EQUALS(";{};;alloc;;use;", getcode("struct Foo { }; Foo *p; p = malloc(10); const Foo *q; q = p;", "p")); ASSERT_EQUALS(";{};;alloc;;use;", getcode("struct Foo { }; Foo *p; p = malloc(10); const Foo *q; q = p;", "p"));
ASSERT_EQUALS(";;alloc;use;", getcode("Fred *fred; p.setFred(fred = new Fred);", "fred"));
// non-use.. // non-use..
ASSERT_EQUALS(";;", getcode("char *s; s = s + 1;", "s")); ASSERT_EQUALS(";;", getcode("char *s; s = s + 1;", "s"));