Fixed #1126 (False positive: upon exception there is memory leak (calling unknown function))
This commit is contained in:
parent
b3b07321ca
commit
83d5a72659
|
@ -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()) ||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue