From d8e64b4cbb97d2501b366ae5e0e87954f4573fa9 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 30 Jun 2022 13:05:28 +0200 Subject: [PATCH] Fix FP leakNoVarFunctionCall (#4243) * Fix #10857 FN: leakNoVarFunctionCall * Fix TODO * Fix #10858 FN: leakNoVarFunctionCall (if ( b && malloc ) ) * #11155 FN: leakNoVarFunctionCall (ternary operator) * Fix #11157 FN: leakNoVarFunctionCall (switch condition) * Fix FN constStatement * Fix FP leakNoVarFunctionCall * Fix FP leakNoVarFunctionCall * Format * Fix FP leakNoVarFunctionCall with unknown function * Fix FP leakNoVarFunctionCall --- lib/checkmemoryleak.cpp | 2 ++ test/testmemleak.cpp | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 517d9fddc..6ce4fa872 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1011,6 +1011,8 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope) functionName == "return") continue; + if (Token::simpleMatch(tok->next()->astParent(), "(")) // passed to another function + continue; if (!tok->isKeyword() && mSettings->library.isNotLibraryFunction(tok)) continue; if (!CheckMemoryLeakInFunction::test_white_list(functionName, mSettings, mTokenizer->isCPP())) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index fbcba2795..9873a1517 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2417,7 +2417,7 @@ private: ASSERT_EQUALS("", errout.str()); check("struct S {\n" - " static void load(const QString & projPath) {\n" + " static void load(const QString& projPath) {\n" " if (proj_)\n" " return;\n" " proj_ = new ProjectT(projPath);\n" @@ -2427,6 +2427,12 @@ private: " static Core::ProjectBase* proj_;\n" "};\n"); ASSERT_EQUALS("", errout.str()); + + check("void f(const std::string& s, int n) {\n" + " std::unique_ptr u;\n" + " u.reset(strcpy(new char[n], s.c_str()));\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); } void missingAssignment() {