Fixed #3039 (False Positive: Memory Leak 'p = pop(p);')
This commit is contained in:
parent
8c093d0f8a
commit
a1aa66f370
|
@ -1113,6 +1113,11 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
||||||
|
|
||||||
if (Token::Match(tok2, "[=+(,] %varid%", varid))
|
if (Token::Match(tok2, "[=+(,] %varid%", varid))
|
||||||
{
|
{
|
||||||
|
if (!rhs && Token::Match(tok2, "[(,]"))
|
||||||
|
{
|
||||||
|
addtoken(&rettail, tok, "use");
|
||||||
|
addtoken(&rettail, tok, ";");
|
||||||
|
}
|
||||||
rhs = true;
|
rhs = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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("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(";;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; f(ab->a);", "ab"));
|
||||||
|
ASSERT_EQUALS(";;use;", getcode("struct AB *ab; ab = pop(ab);", "ab"));
|
||||||
|
|
||||||
// non-use..
|
// non-use..
|
||||||
ASSERT_EQUALS(";;", getcode("char *s; s = s + 1;", "s"));
|
ASSERT_EQUALS(";;", getcode("char *s; s = s + 1;", "s"));
|
||||||
|
|
Loading…
Reference in New Issue