Fixed #3039 (False Positive: Memory Leak 'p = pop(p);')

This commit is contained in:
Daniel Marjamäki 2011-08-28 11:28:14 +02:00
parent 8c093d0f8a
commit a1aa66f370
2 changed files with 6 additions and 0 deletions

View File

@ -1113,6 +1113,11 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
if (Token::Match(tok2, "[=+(,] %varid%", varid))
{
if (!rhs && Token::Match(tok2, "[(,]"))
{
addtoken(&rettail, tok, "use");
addtoken(&rettail, tok, ";");
}
rhs = true;
}
}

View File

@ -488,6 +488,7 @@ private:
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"));
ASSERT_EQUALS(";;use;", getcode("struct AB *ab; f(ab->a);", "ab"));
ASSERT_EQUALS(";;use;", getcode("struct AB *ab; ab = pop(ab);", "ab"));
// non-use..
ASSERT_EQUALS(";;", getcode("char *s; s = s + 1;", "s"));