Detect "var += fclose(f)" as deallocation (fixes false positive #6016)

This commit is contained in:
PKEuS 2014-09-30 13:19:53 +02:00
parent ccb5384645
commit c0e2adf723
2 changed files with 2 additions and 1 deletions

View File

@ -931,7 +931,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
}
}
if (Token::Match(tok->previous(), "[;{})=|] ::| %var%")) {
if (Token::Match(tok->previous(), "[;{})=|+-] ::| %var%")) {
if (Token::Match(tok, "%varid% ?", varid))
tok = tok->tokAt(2);

View File

@ -555,6 +555,7 @@ private:
ASSERT_EQUALS(";;;dealloc;assign;;", getcode(";int res; res = close(res);", "res"));
ASSERT_EQUALS(";;dealloc;", getcode("int f; e |= fclose(f);", "f"));
ASSERT_EQUALS(";;dealloc;", getcode("int f; e += fclose(f);", "f"));
// fcloseall..
ASSERT_EQUALS(";;alloc;;", getcode("char *s; s = malloc(10); fcloseall();", "s"));