File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2745,7 +2745,7 @@ void CheckMemoryLeakNoVar::check()
27452745void CheckMemoryLeakNoVar::checkForUnusedReturnValue (const Scope *scope)
27462746{
27472747 for (const Token *tok = scope->classStart ; tok != scope->classEnd ; tok = tok->next ()) {
2748- if (Token::Match (tok, " %name% (" ) && (!tok->next ()->astParent () || tok->next ()->astParent ()->str () == " !" || tok->next ()->astParent ()->isComparisonOp ())) {
2748+ if (Token::Match (tok, " %name% (" ) && (!tok->next ()->astParent () || tok->next ()->astParent ()->str () == " !" || tok->next ()->astParent ()->isComparisonOp ()) && tok-> next ()-> astOperand1 () == tok ) {
27492749 const AllocType allocType = getAllocationType (tok, 0 );
27502750 if (allocType != No)
27512751 returnValueNotUsedError (tok, tok->str ());
Original file line number Diff line number Diff line change @@ -6503,6 +6503,12 @@ class TestMemleakNoVar : public TestFixture {
65036503 " if(!malloc(5)) fail();\n "
65046504 " }" );
65056505 ASSERT_EQUALS (" [test.cpp:3]: (error) Return value of allocation function malloc is not stored.\n " , errout.str ());
6506+
6507+ check (" FOO* factory() {\n "
6508+ " FOO* foo = new (std::nothrow) FOO;\n "
6509+ " return foo;\n "
6510+ " }" );
6511+ ASSERT_EQUALS (" " , errout.str ());
65066512 }
65076513
65086514 void smartPointerFunctionParam () {
You can’t perform that action at this time.
0 commit comments