memory leak: fixed issue with reporting wrong location

This commit is contained in:
Daniel Marjamäki 2009-03-01 20:34:04 +00:00
parent d4ecddd53c
commit 87b0314e72
3 changed files with 7 additions and 5 deletions

View File

@ -1447,14 +1447,16 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_ParseClass(const Token *
if (tok->isName() || Token::Match(tok, "[;}]"))
{
if (_settings._showAll || !isclass(tok->tokAt(1)))
CheckMemoryLeak_ClassMembers_Variable(classname, tok->strAt(3));
CheckMemoryLeak_ClassMembers_Variable(classname, tok->tokAt(3));
}
}
}
}
void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable(const std::vector<const char *> &classname, const char varname[])
void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable(const std::vector<const char *> &classname, const Token *tokVarname)
{
const char *varname = tokVarname->strAt(0);
// Function pattern.. Check if member function
std::ostringstream fpattern;
for (unsigned int i = 0; i < classname.size(); i++)
@ -1560,7 +1562,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable(const std::vect
if (Alloc != No && Dealloc == No)
{
MemoryLeak(_tokenizer->tokens(), FullVariableName.str().c_str(), Alloc, true);
MemoryLeak(tokVarname, FullVariableName.str().c_str(), Alloc, true);
}
}

View File

@ -58,7 +58,7 @@ private:
}
};
void CheckMemoryLeak_ClassMembers_Variable(const std::vector<const char *> &classname, const char varname[]);
void CheckMemoryLeak_ClassMembers_Variable(const std::vector<const char *> &classname, const Token *tokVarname);
void CheckMemoryLeak_ClassMembers_ParseClass(const Token *tok1, std::vector<const char *> &classname);
void CheckMemoryLeak_ClassMembers();
void CheckMemoryLeak_InFunction();

View File

@ -1327,7 +1327,7 @@ private:
" delete [] str2;\n"
"}\n", true);
ASSERT_EQUALS(std::string("[test.cpp:1]: (all) Memory leak: Fred::str1\n"), errout.str());
ASSERT_EQUALS(std::string("[test.cpp:4]: (all) Memory leak: Fred::str1\n"), errout.str());
}