Fixed #1063 (False positive: deallocated memory doesn't leak upon exception)

This commit is contained in:
Daniel Marjamäki 2009-12-07 19:23:33 +01:00
parent f5849f9be2
commit e5c507dc02
2 changed files with 18 additions and 0 deletions

View File

@ -193,6 +193,15 @@ void CheckExceptionSafety::unsafeNew()
if (tok->next()->varId() && localVars.find(tok->next()->varId()) != localVars.end()) if (tok->next()->varId() && localVars.find(tok->next()->varId()) != localVars.end())
varname = tok->strAt(1); varname = tok->strAt(1);
} }
else if (tok->str() == "delete")
{
if (Token::simpleMatch(tok->next(), varname.c_str()) ||
Token::simpleMatch(tok->next(), ("[ ] " + varname).c_str()))
{
varname = "";
}
}
} }
} }

View File

@ -97,6 +97,15 @@ private:
" A *a2 = new (std::nothrow) A;\n" " A *a2 = new (std::nothrow) A;\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("void a()\n"
"{\n"
" A *a1 = new A;\n"
" delete a1;\n"
" A *a2 = new A;\n"
" delete a2;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void realloc() void realloc()