Fixed #3012 (False Pos Memory Leak with a Macro)

This commit is contained in:
Daniel Marjamäki 2011-08-16 20:39:17 +02:00
parent 4f962acf16
commit 5f25f2c6e6
2 changed files with 17 additions and 4 deletions

View File

@ -272,16 +272,16 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok
CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok, const std::string &varname) const
{
if (Token::simpleMatch(tok, std::string("delete " + varname + " ;").c_str()))
if (Token::Match(tok, std::string("delete " + varname + " [,;]").c_str()))
return New;
if (Token::simpleMatch(tok, std::string("delete [ ] " + varname + " ;").c_str()))
if (Token::Match(tok, std::string("delete [ ] " + varname + " [,;]").c_str()))
return NewArray;
if (Token::simpleMatch(tok, std::string("delete ( " + varname + " ) ;").c_str()))
if (Token::Match(tok, std::string("delete ( " + varname + " ) [,;]").c_str()))
return New;
if (Token::simpleMatch(tok, std::string("delete [ ] ( " + varname + " ) ;").c_str()))
if (Token::Match(tok, std::string("delete [ ] ( " + varname + " ) [,;]").c_str()))
return NewArray;
if (Token::simpleMatch(tok, std::string("free ( " + varname + " ) ;").c_str()) ||

View File

@ -3877,6 +3877,7 @@ private:
TEST_CASE(class19); // ticket #2219
TEST_CASE(class20);
TEST_CASE(class21); // ticket #2517
TEST_CASE(class22); // ticket #3012
TEST_CASE(staticvar);
@ -4769,6 +4770,18 @@ private:
"[test.cpp:10]: (error) Memory leak: A::c\n", errout.str());
}
void class22() // ticket #3012 - false positive
{
check("class Fred {\n"
"private:\n"
" int * a;\n"
"private:\n"
" Fred() { a = new int; }\n"
" ~Fred() { (delete(a), (a)=NULL); }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void staticvar()
{
check("class A\n"