Memory leak: Fixed a false positive

This commit is contained in:
Daniel Marjamäki 2009-01-13 18:30:39 +00:00
parent c8a5bd16a1
commit e664f255a4
2 changed files with 29 additions and 2 deletions

View File

@ -1240,6 +1240,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope(const Token *Tok1, const c
void CheckMemoryLeakClass::CheckMemoryLeak_InFunction()
{
bool classmember = false;
bool infunc = false;
int indentlevel = 0;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
@ -1250,15 +1251,17 @@ void CheckMemoryLeakClass::CheckMemoryLeak_InFunction()
else if (tok->str() == "}")
--indentlevel;
if (tok->str() == "::")
classmember = true;
// In function..
if (indentlevel == 0)
{
if (Token::Match(tok, ") {"))
infunc = true;
infunc = !classmember;
else if (Token::Match(tok, "[;}]"))
infunc = false;
infunc = classmember = false;
}
// Declare a local variable => Check

View File

@ -134,6 +134,7 @@ private:
TEST_CASE(class1);
TEST_CASE(class2);
// TODO TEST_CASE( class3 );
TEST_CASE(class4);
TEST_CASE(throw1);
TEST_CASE(throw2);
@ -1231,6 +1232,29 @@ private:
ASSERT_EQUALS(std::string(""), errout.str());
}
void class4()
{
check("struct MONITOR_POST;\n"
"class MonitorClient\n"
"{\n"
"private:\n"
" void addPost(MONITOR_POST *MonitorPost);\n"
"public:\n"
" void click();\n"
"};\n"
"\n"
"void MonitorClient::addPost(MONITOR_POST* MonitorPost)\n"
"{\n"
" _pMonitorPosts->Add(MonitorPost);\n"
"}\n"
"\n"
"void MonitorClient::click()\n"
"{\n"
" MONITOR_POST *NewMeasurePost = new MONITOR_POST;\n"
" addPost( NewMeasurePost );\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}