Ticket #7680: Properly handle ::delete during memory leak checks.

This commit is contained in:
Simon Martin 2016-09-10 14:54:43 +02:00
parent a50405b8ab
commit f816fb811e
3 changed files with 13 additions and 1 deletions

View File

@ -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 (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)) if (Token::Match(tok, "%varid% ?", varid))
tok = tok->tokAt(2); tok = tok->tokAt(2);

View File

@ -1048,7 +1048,7 @@ static Token * createAstAtToken(Token *tok, bool cpp)
return tok->linkAt(1); return tok->linkAt(1);
if (tok->str() == "return" || !tok->previous() || Token::Match(tok, "%name% %op%|(|[|.|::|<|?|;") || Token::Match(tok->previous(), "[;{}] %cop%|++|--|( !!{")) { 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(); tok = tok->previous();
Token * const tok1 = tok; Token * const tok1 = tok;

View File

@ -365,6 +365,7 @@ private:
TEST_CASE(gnucfg); TEST_CASE(gnucfg);
TEST_CASE(trac3991); TEST_CASE(trac3991);
TEST_CASE(crash); TEST_CASE(crash);
TEST_CASE(trac7680);
} }
std::string getcode(const char code[], const char varname[], bool classfunc=false) { std::string getcode(const char code[], const char varname[], bool classfunc=false) {
@ -3931,6 +3932,14 @@ private:
"}"); "}");
ASSERT_EQUALS("", errout.str()); 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) REGISTER_TEST(TestMemleakInFunction)