diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 7aaeb101d..680e9cdd0 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -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::liststr() == "delete") + return 0; + if (GetAllocationType(tok) != No || GetReallocationType(tok) != No || GetDeallocationType(tok, varnames) != No) return 0; diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 6670fd40b..edaf79e87 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -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()); + } +