Fixed #1912 (False positive: memory leak (calling noreturn function))

This commit is contained in:
Daniel Marjamäki 2010-07-30 08:50:10 +02:00
parent 2e2baa23a6
commit 694325d51f
2 changed files with 6 additions and 26 deletions

View File

@ -2032,21 +2032,9 @@ const Token *CheckMemoryLeakInFunction::findleak(const Token *tokens)
while (last->next())
last = last->next();
// check if we call exit before the end of the funcion
Token *tok2 = last->previous();
if (tok2)
{
if (Token::simpleMatch(tok2, ";"))
{
const Token *tok3 = tok2->previous();
if (tok3 && Token::simpleMatch(tok3, "exit"))
{
return NULL;
}
}
}
return last;
// not a leak if exit is called before the end of the funcion
if (!Token::Match(last->tokAt(-2), "exit|callfunc ; }"))
return last;
}
return NULL;

View File

@ -356,7 +356,6 @@ private:
// Calls to unknown functions.. they may throw exception, quit the program, etc
TEST_CASE(unknownFunction1);
TEST_CASE(unknownFunction2);
TEST_CASE(unknownFunction3);
TEST_CASE(unknownFunction4);
TEST_CASE(unknownFunction5);
@ -805,6 +804,9 @@ private:
ASSERT_EQUALS(notfound, dofindleak("; loop { alloc ; if break; } dealloc ;"));
ASSERT_EQUALS(1, dofindleak("; loop alloc ;"));
ASSERT_EQUALS(1, dofindleak("; loop alloc ; dealloc ;"));
// callfunc (might be noreturn)
ASSERT_EQUALS(notfound, dofindleak("; alloc ; callfunc ; }"));
}
@ -2296,16 +2298,6 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: p\n", errout.str());
}
void unknownFunction3()
{
check("void foo()\n"
"{\n"
" int *p = new int[100];\n"
" ThrowException();\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str());
}
void unknownFunction4()
{
check("void foo()\n"