Fixed #2337 (False Positive: memory leak)

This commit is contained in:
Daniel Marjamäki 2010-12-22 18:32:00 +01:00
parent 3a612d7cd8
commit 00e9822cb3
2 changed files with 3 additions and 2 deletions

View File

@ -1087,7 +1087,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
// Check if the condition depends on var somehow..
bool dep = false;
int innerParlevel = 0;
for (const Token *tok2 = tok; tok2; tok2 = tok2->next())
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next())
{
if (tok2->str() == "(")
++innerParlevel;
@ -1111,7 +1111,6 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
if (innerParlevel > 0 && Token::Match(tok2, "! %varid%", varid))
{
dep = true;
break;
}
if (innerParlevel > 0 && Token::Match(tok2, "%var% (") && !test_white_list(tok2->str()))
{
@ -1132,6 +1131,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
{
addtoken(&rettail, tok, "use");
addtoken(&rettail, tok, ";");
dep = false;
break;
}
}

View File

@ -420,6 +420,7 @@ private:
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"));
ASSERT_EQUALS(";;use;if{}", getcode("char *s; if (!s || x(&s)) { }", "s"));
// switch..
ASSERT_EQUALS(";;switch{case;;break;};", getcode("char *s; switch(a){case 1: break;};", "s"));