Ticket #7680: Properly handle ::delete during memory leak checks.
This commit is contained in:
parent
a50405b8ab
commit
f816fb811e
|
@ -908,6 +908,9 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
|||
}
|
||||
|
||||
if (Token::Match(tok->previous(), "%op%|;|{|}|) ::| %name%") || (Token::Match(tok->previous(), "( ::| %name%") && (!rettail || rettail->str() != "loop"))) {
|
||||
if (tok->str() == "::")
|
||||
tok = tok->next();
|
||||
|
||||
if (Token::Match(tok, "%varid% ?", varid))
|
||||
tok = tok->tokAt(2);
|
||||
|
||||
|
|
|
@ -1048,7 +1048,7 @@ static Token * createAstAtToken(Token *tok, bool cpp)
|
|||
return tok->linkAt(1);
|
||||
|
||||
if (tok->str() == "return" || !tok->previous() || Token::Match(tok, "%name% %op%|(|[|.|::|<|?|;") || Token::Match(tok->previous(), "[;{}] %cop%|++|--|( !!{")) {
|
||||
if (cpp && Token::Match(tok->tokAt(-2), "[;{}] new|delete %name%"))
|
||||
if (cpp && (Token::Match(tok->tokAt(-2), "[;{}] new|delete %name%") || Token::Match(tok->tokAt(-3), "[;{}] :: new|delete %name%")))
|
||||
tok = tok->previous();
|
||||
|
||||
Token * const tok1 = tok;
|
||||
|
|
|
@ -365,6 +365,7 @@ private:
|
|||
TEST_CASE(gnucfg);
|
||||
TEST_CASE(trac3991);
|
||||
TEST_CASE(crash);
|
||||
TEST_CASE(trac7680);
|
||||
}
|
||||
|
||||
std::string getcode(const char code[], const char varname[], bool classfunc=false) {
|
||||
|
@ -3931,6 +3932,14 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void trac7680() {
|
||||
check("void foo() {\n"
|
||||
" int *i = ::new int;\n"
|
||||
" ::delete i;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestMemleakInFunction)
|
||||
|
|
Loading…
Reference in New Issue