Fixed #354 (false positive: memory leak)

This commit is contained in:
Daniel Marjamäki 2009-06-05 08:56:46 +02:00
parent 21e0639443
commit d0f3dccc6d
2 changed files with 20 additions and 2 deletions

View File

@ -657,10 +657,17 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
else if (Token::simpleMatch(tok->next(), "("))
{
int parlevel = 1;
for (const Token *tok2 = tok->tokAt(2); tok2; tok2 = tok2->next())
{
if (tok2->str() == "(" || tok2->str() == ")")
if (tok2->str() == "(")
++parlevel;
else if (tok2->str() == ")")
{
if (parlevel <= 1)
break;
--parlevel;
}
if (tok2->str() == varname)
{

View File

@ -123,6 +123,7 @@ private:
TEST_CASE(ret5); // Bug 2458436 - return use
TEST_CASE(ret6);
TEST_CASE(ret7);
TEST_CASE(ret8);
TEST_CASE(mismatch1);
TEST_CASE(mismatch2);
@ -1094,6 +1095,16 @@ private:
ASSERT_EQUALS("", errout.str());
}
void ret8()
{
check("char *foo()\n"
"{\n"
" char *c = new char[50];\n"
" return ((char *)(c+1));\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void mismatch1()
{