memory leak: don't give false positive when deallocating member variable this->i (#53)

This commit is contained in:
Daniel Marjamäki 2009-01-23 19:24:52 +00:00
parent f31bd86a05
commit ca56520c29
2 changed files with 32 additions and 2 deletions

View File

@ -1461,9 +1461,15 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable(const std::vect
}
// Deallocate..
const char *varnames[2] = { "var", 0 };
const char *varnames[3] = { "var", 0, 0 };
varnames[0] = varname;
AllocType dealloc = GetDeallocationType(tok, varnames);
if (dealloc == No)
{
varnames[0] = "this";
varnames[1] = varname;
dealloc = GetDeallocationType(tok, varnames);
}
if (dealloc != No)
{
std::list<const Token *> callstack;
@ -1473,6 +1479,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable(const std::vect
MismatchError(tok, callstack, FullVariableName.str().c_str());
Dealloc = dealloc;
}
}
}

View File

@ -139,6 +139,7 @@ private:
TEST_CASE(class4);
TEST_CASE(class5);
TEST_CASE(class6);
TEST_CASE(class7);
TEST_CASE(throw1);
TEST_CASE(throw2);
@ -1312,6 +1313,28 @@ private:
ASSERT_EQUALS("", errout.str());
}
void class7()
{
check("class Fred\n"
"{\n"
"public:\n"
" int *i;\n"
" Fred();\n"
" ~Fred();\n"
"};\n"
"\n"
"Fred::Fred()\n"
"{\n"
" this->i = new int;\n"
"}\n"
"Fred::~Fred()\n"
"{\n"
" delete this->i;\n"
"}\n", true);
ASSERT_EQUALS("", errout.str());
}