Fixed #2337 (False Positive: memory leak)
This commit is contained in:
parent
3a612d7cd8
commit
00e9822cb3
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"));
|
||||
|
|
Loading…
Reference in New Issue