Merge pull request #829 from simartin/ticket_7680

Ticket #7680: Properly handle ::delete during memory leak checks.
This commit is contained in:
orbitcowboy 2016-09-10 15:55:31 +02:00 committed by GitHub
commit f0797c3924
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 (tok->str() == "::")
tok = tok->next();
if (Token::Match(tok, "%varid% ?", varid))
tok = tok->tokAt(2);

View File

@ -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;

View File

@ -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)