Fixed #518 (False positive for leaks when function from err()-family used)

This commit is contained in:
Daniel Marjamäki 2009-09-12 14:11:17 +02:00
parent 7479b943cc
commit ab4a7fdef2
2 changed files with 18 additions and 1 deletions

View File

@ -943,11 +943,25 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
addtoken(tok->strAt(0));
// exit..
if (Token::Match(tok->previous(), "[{};] exit ( %any% ) ;"))
if (Token::Match(tok->previous(), "[{};] exit|_exit|_Exit ( %any% ) ;"))
{
addtoken("exit");
tok = tok->tokAt(3);
}
else if (Token::simpleMatch(tok, "abort ( ) ;"))
{
addtoken("exit");
tok = tok->tokAt(2);
}
else if (Token::Match(tok, "err|verr|errx|verrx ("))
{
addtoken("exit");
while (tok->next() && tok->next()->str() != ";")
{
tok = tok->next();
}
}
// Assignment..
if (varid)

View File

@ -384,6 +384,9 @@ private:
// exit..
ASSERT_EQUALS(";;exit;", getcode("char *s; exit(0);", "s"));
ASSERT_EQUALS(";;exit;", getcode("char *s; _exit(0);", "s"));
ASSERT_EQUALS(";;exit;", getcode("char *s; abort();", "s"));
ASSERT_EQUALS(";;exit;", getcode("char *s; err(0);", "s"));
ASSERT_EQUALS(";;if{exit;}", getcode("char *s; if (a) { exit(0); }", "s"));
// open/close