Fixed #627 (False positive with --all, Resource leak with open())

This commit is contained in:
Daniel Marjamäki 2009-08-29 07:43:44 +02:00
parent de9e62e90a
commit ee5b2a43c7
2 changed files with 11 additions and 1 deletions

View File

@ -764,7 +764,14 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
// if else switch
if (tok->str() == "if")
{
if (Token::Match(tok, "if ( %varid% )", varid))
if (alloctype == Fd &&
(Token::Match(tok, "if ( %varid% >= 0 )", varid) ||
Token::Match(tok, "if ( %varid% != -1 )", varid)))
{
addtoken("if(var)");
tok = tok->next()->link();
}
else if (Token::Match(tok, "if ( %varid% )", varid))
{
addtoken("if(var)");

View File

@ -374,6 +374,9 @@ private:
// exit..
ASSERT_EQUALS(";;exit;", getcode("char *s; exit(0);", "s"));
ASSERT_EQUALS(";;if{exit;}", getcode("char *s; if (a) { exit(0); }", "s"));
// open/close
ASSERT_EQUALS(";;alloc;if(var)dealloc;", getcode("int f; f=open(); if(f>=0)close(f);", "f"));
}