diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 4c196dc54..ac39b671c 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -2563,6 +2563,10 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam std::string temp = "this . " + varname; dealloc = getDeallocationType(tok, temp); } + // some usage in the destructor => assume it's related + // to deallocation + if (destructor && tok->str() == varname) + dealloc = CheckMemoryLeak::Many; if (dealloc != CheckMemoryLeak::No) { if (destructor) deallocInDestructor = true; diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 988af3845..fd10d1b0b 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -3812,6 +3812,7 @@ private: TEST_CASE(class20); TEST_CASE(class21); // ticket #2517 TEST_CASE(class22); // ticket #3012 + TEST_CASE(class23); // ticket #3303 TEST_CASE(staticvar); @@ -4695,6 +4696,25 @@ private: ASSERT_EQUALS("", errout.str()); } + void class23() { // ticket #3303 - false positive + check("class CDataImpl {\n" + "public:\n" + " CDataImpl() { m_refcount = 1; }\n" + " void Release() { if (--m_refcount == 0) delete this; }\n" + "private:\n" + " int m_refcount;\n" + "};\n" + "\n" + "class CData {\n" + "public:\n" + " CData() : m_impl(new CDataImpl()) { }\n" + " ~CData() { if (m_impl) m_impl->Release(); }\n" + "private:\n" + " CDataImpl *m_impl;\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } + void staticvar() { check("class A\n" "{\n"