Fixed #2802 (False positive: ::free() is not recognised as free() to release buffers)
This commit is contained in:
parent
5c0cab238f
commit
e6f761126c
|
@ -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)
|
||||
|
|
|
@ -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;",
|
||||
|
|
Loading…
Reference in New Issue