memory leaks: minor refactorings
This commit is contained in:
parent
f4b6c822d3
commit
5df28c51c6
|
@ -1986,6 +1986,9 @@ void CheckMemoryLeakInClass::parseClass(const Token *tok1, std::vector<const cha
|
|||
|
||||
void CheckMemoryLeakInClass::variable(const char classname[], const Token *tokVarname)
|
||||
{
|
||||
if (!_settings->_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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue