Merge branch 'memleak'

This commit is contained in:
Daniel Marjamäki 2009-10-12 21:36:47 +02:00
commit be0c79f36c
2 changed files with 19 additions and 0 deletions

View File

@ -523,6 +523,8 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
int par = 1;
int parlevel = 0;
const bool dot(tok->previous()->str() == ".");
for (; tok; tok = tok->next())
{
if (tok->str() == "(")
@ -542,6 +544,9 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
++par;
if (varid > 0 && Token::Match(tok, "[,()] %varid% [,()]", varid))
{
if (dot)
return "use";
const Token *ftok = _tokenizer->getFunctionTokenByName(funcname.c_str());
if (!ftok)
return "use";

View File

@ -271,6 +271,8 @@ private:
// Unknown syntax
TEST_CASE(unknownSyntax1);
TEST_CASE(knownFunctions);
TEST_CASE(same_function_name);
}
@ -2393,6 +2395,18 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str());
}
void same_function_name()
{
check("void a(char *p)\n"
"{ }\n"
"void b()\n"
"{\n"
" char *p = malloc(10);\n"
" abc.a(p);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
};
static TestMemleakInFunction testMemleakInFunction;