Fixed #2855 (False positive: resource leak when reusing fd)

This commit is contained in:
Daniel Marjamäki 2011-06-29 20:00:21 +02:00
parent edae93a68a
commit cacca00080
2 changed files with 12 additions and 0 deletions

View File

@ -972,6 +972,17 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
}
else
{
if (Token::Match(tok, "%varid% = close ( %varid% )", varid))
{
addtoken(&rettail, tok, "dealloc");
addtoken(&rettail, tok, ";");
addtoken(&rettail, tok, "assign");
addtoken(&rettail, tok, ";");
tok = tok->tokAt(5);
continue;
}
// var = strcpy|.. ( var ,
if (Token::Match(tok, "[;{}] %varid% = memcpy|memmove|memset|strcpy|strncpy|strcat|strncat ( %varid% ,", varid))
{

View File

@ -517,6 +517,7 @@ private:
ASSERT_EQUALS(";;alloc;if(var){dealloc;}", getcode("int f; f=open(); if(f>=0)close(f);", "f"));
ASSERT_EQUALS(";;alloc;ifv{;}", getcode("int f; f=open(); if(f!=-1 || x);", "f"));
ASSERT_EQUALS(";;;dealloc;loop{}}", getcode(";int f; while (close(f) == -1) { } }", "f"));
ASSERT_EQUALS(";;;dealloc;assign;;}", getcode(";int res; res = close(res); }", "res"));
ASSERT_EQUALS(";;dealloc;", getcode("int f; e |= fclose(f);", "f"));