memory leak: handle 'delete (p)' and 'delete [] (p)'. Fixes ticket 102
This commit is contained in:
parent
17fbab018c
commit
5c1995ca81
|
@ -173,6 +173,12 @@ CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetDeallocationType(const
|
|||
if (Token::simpleMatch(tok, std::string("delete [ ] " + names + " ;").c_str()))
|
||||
return NewArray;
|
||||
|
||||
if (Token::simpleMatch(tok, std::string("delete ( " + names + " ) ;").c_str()))
|
||||
return New;
|
||||
|
||||
if (Token::simpleMatch(tok, std::string("delete [ ] ( " + names + " ) ;").c_str()))
|
||||
return NewArray;
|
||||
|
||||
if (Token::simpleMatch(tok, std::string("free ( " + names + " ) ;").c_str()) ||
|
||||
Token::simpleMatch(tok, std::string("kfree ( " + names + " ) ;").c_str()))
|
||||
{
|
||||
|
@ -214,6 +220,10 @@ const char * CheckMemoryLeakClass::call_func(const Token *tok, std::list<const T
|
|||
if (Token::Match(tok, "atoi|atof|atol|strtol|strtoul|strtod"))
|
||||
return 0;
|
||||
|
||||
// This is not an unknown function neither
|
||||
if (tok->str() == "delete")
|
||||
return 0;
|
||||
|
||||
if (GetAllocationType(tok) != No || GetReallocationType(tok) != No || GetDeallocationType(tok, varnames) != No)
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -148,6 +148,7 @@ private:
|
|||
TEST_CASE(class6);
|
||||
TEST_CASE(class7);
|
||||
TEST_CASE(class8);
|
||||
TEST_CASE(class9);
|
||||
|
||||
TEST_CASE(throw1);
|
||||
TEST_CASE(throw2);
|
||||
|
@ -1453,6 +1454,24 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void class9()
|
||||
{
|
||||
check("class A\n"
|
||||
"{\n"
|
||||
"public:\n"
|
||||
" int * p;\n"
|
||||
" A();\n"
|
||||
" ~A();\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"A::A()\n"
|
||||
"{ p = new int; }\n"
|
||||
"\n"
|
||||
"A::~A()\n"
|
||||
"{ delete (p); }\n", true);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue