Fixed #2313 (False Positive: memory leak)

This commit is contained in:
Daniel Marjamäki 2010-12-17 21:34:22 +01:00
parent 7050e9610b
commit 814efb2512
2 changed files with 3 additions and 1 deletions

View File

@ -1122,7 +1122,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
tok3 = tok3->link(); tok3 = tok3->link();
else if (tok3->str() == ")") else if (tok3->str() == ")")
break; break;
else if (Token::Match(tok3->previous(), "(|, %varid% ,|)", varid)) else if (Token::Match(tok3->previous(), "(|, &| %varid% ,|)", varid))
{ {
use = true; use = true;
break; break;

View File

@ -418,6 +418,8 @@ private:
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")); ASSERT_EQUALS(";;alloc;if(var){dealloc;}", getcode("int fd = open(a,b); if (0 < fd) { close(fd); }", "fd"));
ASSERT_EQUALS(";;use;if{}", getcode("char *s; if (x(s)) { }", "s"));
ASSERT_EQUALS(";;use;if{}", getcode("char *s; if (x(&s)) { }", "s"));
// 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"));