Fixed #2262 (False positive: Resource leak: fd)
This commit is contained in:
parent
234b1e0098
commit
6761765a70
|
@ -1069,7 +1069,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
||||||
{
|
{
|
||||||
if (alloctype == Fd)
|
if (alloctype == Fd)
|
||||||
{
|
{
|
||||||
if (Token::Match(tok, "if ( 0 <= %varid% )", varid) ||
|
if (Token::Match(tok, "if ( 0 <=|< %varid% )", varid) ||
|
||||||
Token::Match(tok, "if ( %varid% != -1 )", varid))
|
Token::Match(tok, "if ( %varid% != -1 )", varid))
|
||||||
{
|
{
|
||||||
addtoken(&rettail, tok, "if(var)");
|
addtoken(&rettail, tok, "if(var)");
|
||||||
|
|
|
@ -496,6 +496,7 @@ private:
|
||||||
ASSERT_EQUALS(";;ifv{}", getcode("char *s; if (foo(!s)) { }", "s"));
|
ASSERT_EQUALS(";;ifv{}", getcode("char *s; if (foo(!s)) { }", "s"));
|
||||||
ASSERT_EQUALS(";;;if{dealloc;};if{dealloc;return;}assign;returnuse;", getcode("char *buf, *tmp; tmp = realloc(buf, 40); if (!(tmp)) { free(buf); return; } buf = tmp; return buf;", "buf"));
|
ASSERT_EQUALS(";;;if{dealloc;};if{dealloc;return;}assign;returnuse;", getcode("char *buf, *tmp; tmp = realloc(buf, 40); if (!(tmp)) { free(buf); return; } buf = tmp; return buf;", "buf"));
|
||||||
ASSERT_EQUALS(";;if{}", getcode("FILE *f; if (fgets(buf,100,f)){}", "f"));
|
ASSERT_EQUALS(";;if{}", getcode("FILE *f; if (fgets(buf,100,f)){}", "f"));
|
||||||
|
ASSERT_EQUALS(";;alloc;if(var){dealloc;}", getcode("int fd = open(a,b); if (0 < fd) { close(fd); }", "fd"));
|
||||||
|
|
||||||
// switch..
|
// switch..
|
||||||
ASSERT_EQUALS(";;switch{case;;break;};", getcode("char *s; switch(a){case 1: break;};", "s"));
|
ASSERT_EQUALS(";;switch{case;;break;};", getcode("char *s; switch(a){case 1: break;};", "s"));
|
||||||
|
|
Loading…
Reference in New Issue