Fixed #3695 (False positive: memory leak (ptr?free(ptr):0))
This commit is contained in:
parent
643f3890b4
commit
0ead18122d
|
@ -269,7 +269,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok
|
|||
if (tok && tok->str() == "::")
|
||||
tok = tok->next();
|
||||
|
||||
if (Token::Match(tok, "free|kfree ( %varid% ) ;", varid) ||
|
||||
if (Token::Match(tok, "free|kfree ( %varid% ) [;:]", varid) ||
|
||||
Token::Match(tok, "free|kfree ( %varid% -", varid) ||
|
||||
Token::Match(tok, "realloc ( %varid% , 0 ) ;", varid))
|
||||
return Malloc;
|
||||
|
@ -989,6 +989,9 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
|||
}
|
||||
|
||||
if (Token::Match(tok->previous(), "[;{})=|] ::| %var%")) {
|
||||
if (Token::Match(tok, "%varid% ?", varid))
|
||||
tok = tok->tokAt(2);
|
||||
|
||||
AllocType dealloc = getDeallocationType(tok, varid);
|
||||
|
||||
if (dealloc != No && tok->str() == "fcloseall" && alloctype != dealloc)
|
||||
|
|
|
@ -436,6 +436,7 @@ private:
|
|||
ASSERT_EQUALS(";;dealloc;", getcode("void *p; foo(close(p));", "p"));
|
||||
ASSERT_EQUALS(";;;;", getcode("FILE *f1; FILE *f2; fclose(f1);", "f2"));
|
||||
ASSERT_EQUALS(";;returnuse;", getcode("FILE *f; return fclose(f) == EOF ? 1 : 2;", "f"));
|
||||
ASSERT_EQUALS(";;dealloc;", getcode("char *s; s ? free(s) : 0;", "s"));
|
||||
|
||||
// if..
|
||||
ASSERT_EQUALS(";;if{}", getcode("char *s; if (a) { }", "s"));
|
||||
|
|
Loading…
Reference in New Issue