diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index f951b876b..678864bfb 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -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::listprevious(), "[;{})=|] %var%")) { + if (Token::Match(tok->previous(), "[;{})=|] ::| %var%")) { AllocType dealloc = getDeallocationType(tok, varid); if (dealloc != No && tok->str() == "fcloseall" && alloctype != dealloc) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index bf4bbb2a0..8178ccb49 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -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(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;",