From 6336372fb47b049ac9d056cad77c390aaab8b874 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Tue, 10 Nov 2015 14:19:25 +0100 Subject: [PATCH] Apply same heuristics in CheckMemoryLeakNoVar::checkForUnusedReturnValue() as in CheckOther::checkIgnoredReturnValue(): Ensure that a defined function has non-void return value. (#6693) --- lib/checkmemoryleak.cpp | 3 ++- test/testmemleak.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 13ba90dc9..130096eb3 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -2755,7 +2755,8 @@ void CheckMemoryLeakNoVar::check() void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope) { for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { - if (!tok->varId() && Token::Match(tok, "%name% (") && (!tok->next()->astParent() || tok->next()->astParent()->str() == "!" || tok->next()->astParent()->isComparisonOp()) && tok->next()->astOperand1() == tok) { + if (!tok->varId() && Token::Match(tok, "%name% (") && (!tok->function() || !Token::Match(tok->function()->retDef, "void %name%")) + && (!tok->next()->astParent() || tok->next()->astParent()->str() == "!" || tok->next()->astParent()->isComparisonOp()) && tok->next()->astOperand1() == tok) { const AllocType allocType = getAllocationType(tok, 0); if (allocType != No) returnValueNotUsedError(tok, tok->str()); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 912f8be58..292fc0f2b 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -6360,6 +6360,16 @@ private: " S socket(i);\n" "}"); ASSERT_EQUALS("", errout.str()); + + // Ticket #6693 + check("struct CTest {\n" + " void Initialise();\n" + " void malloc();\n" + "};\n" + "void CTest::Initialise() {\n" + " malloc();\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void smartPointerFunctionParam() {