Fixed #1820 (False positive: memory leak (auto deallocated class))
This commit is contained in:
parent
bf7ce98178
commit
ae3557fa92
|
@ -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)
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue