Fixed #1820 (False positive: memory leak (auto deallocated class))

This commit is contained in:
Daniel Marjamäki 2010-07-05 14:01:25 +02:00
parent bf7ce98178
commit ae3557fa92
2 changed files with 26 additions and 0 deletions

View File

@ -943,6 +943,20 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
alloc = No; alloc = No;
} }
} }
else if (Token::Match(tok->tokAt(2), "new ( nothrow ) %type%"))
{
if (isclass(_tokenizer, tok->tokAt(6)))
{
alloc = No;
}
}
else if (Token::Match(tok->tokAt(2), "new ( std :: nothrow ) %type%"))
{
if (isclass(_tokenizer, tok->tokAt(8)))
{
alloc = No;
}
}
} }
if (alloc != No) if (alloc != No)

View File

@ -889,6 +889,18 @@ private:
" delete p;\n" " delete p;\n"
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Mismatching allocation and deallocation: p\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Mismatching allocation and deallocation: p\n", errout.str());
check("void f()\n"
"{\n"
" Fred *f = new(nothrow) Fred;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f()\n"
"{\n"
" Fred *f = new(std::nothrow) Fred;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }