Fixed #6989 (incorrect memleak error)

This commit is contained in:
Daniel Marjamäki 2016-05-21 14:03:28 +02:00
parent a5dc76d50c
commit c23c1f245c
2 changed files with 10 additions and 1 deletions

View File

@ -524,8 +524,11 @@ void CheckLeakAutoVar::functionCall(const Token *tok, VarInfo *varInfo, const Va
return;
for (const Token *arg = tok->tokAt(2); arg; arg = arg->nextArgument()) {
if (_tokenizer->isCPP() && arg->str() == "new")
if (_tokenizer->isCPP() && arg->str() == "new") {
arg = arg->next();
if (Token::simpleMatch(arg, "( std :: nothrow )"))
arg = arg->tokAt(5);
}
if (Token::Match(arg, "%var% [-,)] !!.") || Token::Match(arg, "& %var%")) {

View File

@ -1207,6 +1207,12 @@ private:
" m_dsmccQueue.enqueue(new DSMCCPacket(somethingunrelated));\n"
"}", true);
ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: dataCopy\n", errout.str());
check("void f() {\n"
" char *buf = new char[1000];\n"
" clist.push_back(new (std::nothrow) C(buf));\n"
"}", true);
ASSERT_EQUALS("[test.cpp:4]: (information) --check-library: Function C() should have <use>/<leak-ignore> configuration\n", errout.str());
}
void testKeywords() {