diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 6ddad4fc1..0862433c2 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -1986,6 +1986,9 @@ void CheckMemoryLeakInClass::parseClass(const Token *tok1, std::vector_showAll) + return; + const char *varname = tokVarname->strAt(0); // Check if member variable has been allocated and deallocated.. @@ -2075,7 +2078,7 @@ void CheckMemoryLeakInClass::variable(const char classname[], const Token *tokVa functionToken = Tokenizer::findClassFunction(functionToken->next(), classname, "~| %var%", indent_); } - if (_settings->_showAll && Alloc != CheckMemoryLeak::No && Dealloc == CheckMemoryLeak::No) + if (Alloc != CheckMemoryLeak::No && Dealloc == CheckMemoryLeak::No) { memoryLeak(tokVarname, (std::string(classname) + "::" + varname).c_str(), Alloc, true); } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 226172251..5eba13172 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2361,6 +2361,8 @@ private: TEST_CASE(class10); TEST_CASE(class11); + TEST_CASE(use); + TEST_CASE(free_member_in_sub_func); } @@ -2577,6 +2579,23 @@ private: } + void use() + { + check("class A\n" + "{\n" + "public:\n" + " Fred * fred;\n" + " A();\n" + "};\n" + "A::A()\n" + "{\n" + " fred = new Fred;\n" + " list->push_back(fred);\n" + "}", true); + TODO_ASSERT_EQUALS("", errout.str()); + } + + void free_member_in_sub_func() { // Member function