diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 8d02e87e1..b9eb70d62 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1070,7 +1070,7 @@ void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope) if (closingBrace->str() == "}" && Token::Match(closingBrace->link()->tokAt(-1), "%name%") && (!isNew && precedes(tok, closingBrace->link()))) continue; returnValueNotUsedError(tok, tok->str()); - } else if (Token::Match(parent, "%comp%|!|,")) { + } else if (Token::Match(parent, "%comp%|!|,|%oror%|&&")) { if (!(parent->astParent() && parent->str() == ",")) returnValueNotUsedError(tok, tok->str()); } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 6d845c4e9..717212db8 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2601,6 +2601,12 @@ private: " C{ new QWidget, 1 };\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("void f(bool b) { if (b && malloc(42)) {} }\n" // // #10858 + "void g(bool b) { if (b || malloc(42)) {} }\n"); + ASSERT_EQUALS("[test.cpp:1]: (error) Return value of allocation function 'malloc' is not stored.\n" + "[test.cpp:2]: (error) Return value of allocation function 'malloc' is not stored.\n", + errout.str()); } void smartPointerFunctionParam() {