Fix #299 (Memory leak not detected when parameters contain ::)

http://apps.sourceforge.net/trac/cppcheck/ticket/299
This commit is contained in:
Reijo Tomperi 2009-05-21 22:51:19 +03:00
parent bce4488475
commit e6017ad54b
2 changed files with 9 additions and 2 deletions

View File

@ -1384,6 +1384,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope(const Token *Tok1, const c
void CheckMemoryLeakClass::CheckMemoryLeak_InFunction() void CheckMemoryLeakClass::CheckMemoryLeak_InFunction()
{ {
bool classmember = false; bool classmember = false;
bool beforeParameters = false;
bool infunc = false; bool infunc = false;
int indentlevel = 0; int indentlevel = 0;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
@ -1400,11 +1401,17 @@ void CheckMemoryLeakClass::CheckMemoryLeak_InFunction()
if (Token::simpleMatch(tok, ") {")) if (Token::simpleMatch(tok, ") {"))
infunc = true; infunc = true;
else if (tok->str() == "::") else if (tok->str() == "(")
beforeParameters = false;
else if (tok->str() == "::" && beforeParameters)
classmember = true; classmember = true;
else if (Token::Match(tok, "[;}]")) else if (Token::Match(tok, "[;}]"))
{
infunc = classmember = false; infunc = classmember = false;
beforeParameters = true;
}
} }
// Declare a local variable => Check // Declare a local variable => Check

View File

@ -2165,7 +2165,7 @@ private:
std::string err(errout.str()); std::string err(errout.str());
TODO_ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Memory leak: out\n"), err); ASSERT_EQUALS(std::string("[test.cpp:5]: (error) Memory leak: out\n"), err);
} }
void strndup_function() void strndup_function()