Fixed #1126 (False positive: upon exception there is memory leak (calling unknown function))

This commit is contained in:
Daniel Marjamäki 2009-12-21 20:04:55 +01:00
parent b3b07321ca
commit 83d5a72659
2 changed files with 23 additions and 1 deletions

View File

@ -177,7 +177,7 @@ void CheckExceptionSafety::unsafeNew()
localVars.insert(tok->varId());
}
if (Token::Match(tok, "; %var% = new %type%"))
if (Token::Match(tok, "[;{}] %var% = new %type%"))
{
if (!varname.empty())
{
@ -188,6 +188,19 @@ void CheckExceptionSafety::unsafeNew()
varname = tok->strAt(1);
}
else if (Token::Match(tok, "[;{}] %var% ("))
{
for (tok = tok->next(); tok && !Token::Match(tok, "[;{}]"); tok = tok->next())
{
if (tok->str() == varname)
{
varname = "";
}
}
if (!tok)
break;
}
else if (tok->str() == "delete")
{
if (Token::simpleMatch(tok->next(), varname.c_str()) ||

View File

@ -113,6 +113,15 @@ private:
" B *b = new B;\n"
"}\n", "A\n");
ASSERT_EQUALS("", errout.str());
// passing pointer to unknown function.. the pointer may be added to some list etc..
check("void f()\n"
"{\n"
" A *a1 = new A;\n"
" add(a1);\n"
" A *a2 = new A;\n"
"}\n", "");
ASSERT_EQUALS("", errout.str());
}
void realloc()