Fixed #1616 (false positive - Upon exception there is a memory leak)

This commit is contained in:
Daniel Marjamäki 2010-04-24 14:51:10 +02:00
parent f3bea249ac
commit 6b52730d4e
2 changed files with 24 additions and 0 deletions

View File

@ -190,6 +190,10 @@ void CheckExceptionSafety::unsafeNew()
else if (Token::Match(tok, "[;{}] %var% ("))
{
// False negatives: we don't handle switch cases properly so we just bail out.
if (tok->strAt(1) == "switch")
break;
for (tok = tok->next(); tok && !Token::Match(tok, "[;{}]"); tok = tok->next())
{
if (tok->str() == varname)

View File

@ -36,6 +36,7 @@ private:
{
TEST_CASE(destructors);
TEST_CASE(newnew);
TEST_CASE(switchnewnew);
TEST_CASE(realloc);
TEST_CASE(deallocThrow);
}
@ -124,6 +125,25 @@ private:
ASSERT_EQUALS("", errout.str());
}
void switchnewnew()
{
check("int *f(int x)\n"
"{\n"
" int *p = 0;\n"
" switch(x)\n"
" {\n"
" case 1:\n"
" p = new int(10);\n"
" break;\n"
" case 2:\n"
" p = new int(100);\n"
" break;\n"
" };\n"
" return p;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void realloc()
{
check("class A\n"