Fixed #2802 (False positive: ::free() is not recognised as free() to release buffers)

This commit is contained in:
Daniel Marjamäki 2012-07-24 09:28:08 +02:00
parent 5c0cab238f
commit e6f761126c
2 changed files with 5 additions and 1 deletions

View File

@ -266,6 +266,9 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok
if (Token::Match(tok, "delete [ ] ( %varid% ) ;", varid))
return NewArray;
if (tok && tok->str() == "::")
tok = tok->next();
if (Token::Match(tok, "free|kfree ( %varid% ) ;", varid) ||
Token::Match(tok, "free|kfree ( %varid% -", varid) ||
Token::Match(tok, "realloc ( %varid% , 0 ) ;", varid))
@ -985,7 +988,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
}
}
if (Token::Match(tok->previous(), "[;{})=|] %var%")) {
if (Token::Match(tok->previous(), "[;{})=|] ::| %var%")) {
AllocType dealloc = getDeallocationType(tok, varid);
if (dealloc != No && tok->str() == "fcloseall" && alloctype != dealloc)

View File

@ -425,6 +425,7 @@ private:
ASSERT_EQUALS(";;dealloc;", getcode("char *s; free((void *)s);", "s"));
ASSERT_EQUALS(";;dealloc;", getcode("char *s; free((void *)(s));", "s"));
ASSERT_EQUALS(";;dealloc;", getcode("char *s; free(reinterpret_cast<void *>(s));", "s"));
ASSERT_EQUALS(";;dealloc;", getcode("char *s; ::free(s);", "s")); // #2802
ASSERT_EQUALS(";;dealloc;", getcode("char *s; delete s;", "s"));
ASSERT_EQUALS(";;dealloc;", getcode("char *s; delete (s);", "s"));
TODO_ASSERT_EQUALS(";;dealloc;",