From bfa26b5a7232ff2368871cbbe07c68d120a6acf5 Mon Sep 17 00:00:00 2001 From: keinflue <80230456+keinflue@users.noreply.github.com> Date: Sat, 8 May 2021 08:26:10 +0000 Subject: [PATCH] Fix FP leakNoVarFunctionCall with passthrough returns (#3249) --- lib/checkmemoryleak.cpp | 2 +- test/testmemleak.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 0943c9c9d..72580f6e6 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -996,7 +996,7 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope) const Token* tok2 = tok->next()->astParent(); while (tok2 && tok2->isCast()) tok2 = tok2->astParent(); - if (tok2 && tok2->isAssignmentOp()) + if (Token::Match(tok2, "%assign%|return")) continue; const std::string& functionName = tok->str(); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index ab92b6505..5fe10a408 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2173,6 +2173,11 @@ private: " return ret;\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("char *x() {\n" + " return strcpy(malloc(10), \"abc\");\n" + "}"); + ASSERT_EQUALS("", errout.str()); check("void x() {\n" " free(malloc(10));\n"