diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 7c0013abe..be1c508e2 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -632,14 +632,14 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam if (destructor) deallocInDestructor = true; - // several types of allocation/deallocation? - if (memberDealloc != CheckMemoryLeak::No && memberDealloc != dealloc) - dealloc = CheckMemoryLeak::Many; - if (dealloc != CheckMemoryLeak::Many && memberAlloc != CheckMemoryLeak::No && memberAlloc != Many && memberAlloc != dealloc) { mismatchAllocDealloc({tok}, classname + "::" + varname); } + // several types of allocation/deallocation? + if (memberDealloc != CheckMemoryLeak::No && memberDealloc != dealloc) + dealloc = CheckMemoryLeak::Many; + memberDealloc = dealloc; } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index df9539cbd..1dd2b8d22 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -1571,6 +1571,18 @@ private: " delete [] pkt_buffer;\n" "}"); ASSERT_EQUALS("[test.cpp:14]: (error) Mismatching allocation and deallocation: A::pkt_buffer\n", errout.str()); + + check("struct S {\n" // 5678 + " ~S();\n" + " void f();\n" + " int* p;\n" + "};\n" + "void S::f() {\n" + " p = new char[1];\n" + " delete p;\n" + " p = 0;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:8]: (error) Mismatching allocation and deallocation: S::p\n", errout.str()); } void mismatch2() { // #5659