Fixed #2855 (False positive: resource leak when reusing fd)
This commit is contained in:
parent
edae93a68a
commit
cacca00080
|
@ -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))
|
||||
{
|
||||
|
|
|
@ -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"));
|
||||
|
||||
|
|
Loading…
Reference in New Issue