memory leaks: minor refactorings

This commit is contained in:
Daniel Marjamäki 2009-09-12 21:13:47 +02:00
parent f4b6c822d3
commit 5df28c51c6
2 changed files with 23 additions and 1 deletions

View File

@ -1986,6 +1986,9 @@ void CheckMemoryLeakInClass::parseClass(const Token *tok1, std::vector<const cha
void CheckMemoryLeakInClass::variable(const char classname[], const Token *tokVarname) void CheckMemoryLeakInClass::variable(const char classname[], const Token *tokVarname)
{ {
if (!_settings->_showAll)
return;
const char *varname = tokVarname->strAt(0); const char *varname = tokVarname->strAt(0);
// Check if member variable has been allocated and deallocated.. // 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_); 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); memoryLeak(tokVarname, (std::string(classname) + "::" + varname).c_str(), Alloc, true);
} }

View File

@ -2361,6 +2361,8 @@ private:
TEST_CASE(class10); TEST_CASE(class10);
TEST_CASE(class11); TEST_CASE(class11);
TEST_CASE(use);
TEST_CASE(free_member_in_sub_func); 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() void free_member_in_sub_func()
{ {
// Member function // Member function