Fixed #3012 (False Pos Memory Leak with a Macro)
This commit is contained in:
parent
4f962acf16
commit
5f25f2c6e6
|
@ -272,16 +272,16 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok
|
||||||
|
|
||||||
CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok, const std::string &varname) const
|
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;
|
return New;
|
||||||
|
|
||||||
if (Token::simpleMatch(tok, std::string("delete [ ] " + varname + " ;").c_str()))
|
if (Token::Match(tok, std::string("delete [ ] " + varname + " [,;]").c_str()))
|
||||||
return NewArray;
|
return NewArray;
|
||||||
|
|
||||||
if (Token::simpleMatch(tok, std::string("delete ( " + varname + " ) ;").c_str()))
|
if (Token::Match(tok, std::string("delete ( " + varname + " ) [,;]").c_str()))
|
||||||
return New;
|
return New;
|
||||||
|
|
||||||
if (Token::simpleMatch(tok, std::string("delete [ ] ( " + varname + " ) ;").c_str()))
|
if (Token::Match(tok, std::string("delete [ ] ( " + varname + " ) [,;]").c_str()))
|
||||||
return NewArray;
|
return NewArray;
|
||||||
|
|
||||||
if (Token::simpleMatch(tok, std::string("free ( " + varname + " ) ;").c_str()) ||
|
if (Token::simpleMatch(tok, std::string("free ( " + varname + " ) ;").c_str()) ||
|
||||||
|
|
|
@ -3877,6 +3877,7 @@ private:
|
||||||
TEST_CASE(class19); // ticket #2219
|
TEST_CASE(class19); // ticket #2219
|
||||||
TEST_CASE(class20);
|
TEST_CASE(class20);
|
||||||
TEST_CASE(class21); // ticket #2517
|
TEST_CASE(class21); // ticket #2517
|
||||||
|
TEST_CASE(class22); // ticket #3012
|
||||||
|
|
||||||
TEST_CASE(staticvar);
|
TEST_CASE(staticvar);
|
||||||
|
|
||||||
|
@ -4769,6 +4770,18 @@ private:
|
||||||
"[test.cpp:10]: (error) Memory leak: A::c\n", errout.str());
|
"[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()
|
void staticvar()
|
||||||
{
|
{
|
||||||
check("class A\n"
|
check("class A\n"
|
||||||
|
|
Loading…
Reference in New Issue