Fixed #627 (False positive with --all, Resource leak with open())
This commit is contained in:
parent
de9e62e90a
commit
ee5b2a43c7
|
@ -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)");
|
||||
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue