Fix ticket #371 (Resource leak when exit() and if() uses together)
http://apps.sourceforge.net/trac/cppcheck/ticket/371
This commit is contained in:
parent
5747133fa8
commit
9bac4aca75
|
@ -809,13 +809,26 @@ void CheckMemoryLeakClass::simplifycode(Token *tok, bool &all)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Found an "exit".. try to remove everything before it
|
// Found an "exit".. try to remove everything before it
|
||||||
const Token *tokEnd = tok2->next();
|
Token *tokEnd = tok2->next();
|
||||||
while (tok2->previous() && !Token::Match(tok2->previous(), "[{}]"))
|
int indentlevel = 0;
|
||||||
tok2 = tok2->previous();
|
while (tok2->previous())
|
||||||
if (tok2->previous())
|
{
|
||||||
tok2 = tok2->previous();
|
tok2 = tok2->previous();
|
||||||
|
if (tok2->str() == "}")
|
||||||
|
{
|
||||||
|
indentlevel--;
|
||||||
|
}
|
||||||
|
else if (tok2->str() == "{")
|
||||||
|
{
|
||||||
|
if (indentlevel == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
indentlevel++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Token::eraseTokens(tok2, tokEnd);
|
Token::eraseTokens(tok2, tokEnd);
|
||||||
|
tok2 = tokEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reduce the code..
|
// reduce the code..
|
||||||
|
|
|
@ -2234,6 +2234,14 @@ private:
|
||||||
" exit(0);\n"
|
" exit(0);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" char *out = new char[100];\n"
|
||||||
|
" if( out ) {}\n"
|
||||||
|
" exit(0);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void stdstring()
|
void stdstring()
|
||||||
|
|
Loading…
Reference in New Issue