Fixed #2248 (memory leak : pointer inserted in an object)

This commit is contained in:
Daniel Marjamäki 2010-11-29 19:53:34 +01:00
parent 6bf0e7eb08
commit 4de64209fb
2 changed files with 3 additions and 16 deletions

View File

@ -1382,21 +1382,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
Token::Match(tok, "= strcpy|strcat|memmove|memcpy ( %varid% ,", varid) ||
Token::Match(tok, "[;{}] %var% [ %varid% ]", varid))
{
bool used = true;
if (Token::Match(tok->tokAt(-2), "; %var% = %varid%", varid))
{
const unsigned int varid2(tok->previous()->varId());
if (Token::Match(tok->tokAt(-6), "const %type% * %varid% ;", varid2) ||
Token::Match(tok->tokAt(-7), "const struct %type% * %varid% ;", varid2))
{
// address is taken by pointer constant
used = false;
}
}
if (used)
addtoken(&rettail, tok, "use");
addtoken(&rettail, tok, "use");
}
else if (Token::Match(tok->previous(), "[;{}=(,+-*/] %varid% [", varid))
{

View File

@ -531,8 +531,9 @@ private:
ASSERT_EQUALS(";;use;", getcode("char *s; s2 = x + s;", "s"));
ASSERT_EQUALS(";;use;if{;}", getcode("char *s; if (foo(s)) ;", "s"));
ASSERT_EQUALS(";;use;", getcode("char *s; map1[s] = 0;", "s"));
ASSERT_EQUALS(";;;;", 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(";{};;alloc;;use;", getcode("struct Foo { }; Foo *p; p = malloc(10); const Foo *q; q = p;", "p"));
// non-use..
ASSERT_EQUALS(";;", getcode("char *s; s = s + 1;", "s"));