From 06b408ea205d0b056d83855dd420b77314bfdae3 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 29 Jun 2022 13:43:17 +0200 Subject: [PATCH] Fix FP leakNoVarFunctionCall with unknown function (#4242) * 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 --- lib/checkmemoryleak.cpp | 2 ++ test/testmemleak.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index cbb2a20ef..517d9fddc 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1011,6 +1011,8 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope) functionName == "return") continue; + if (!tok->isKeyword() && mSettings->library.isNotLibraryFunction(tok)) + continue; if (!CheckMemoryLeakInFunction::test_white_list(functionName, mSettings, mTokenizer->isCPP())) continue; diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 176482c7b..fbcba2795 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2415,6 +2415,18 @@ private: " return *strings_.insert(it, std::strcpy(new char[std::strlen(s) + 1], s));\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("struct S {\n" + " static void load(const QString & projPath) {\n" + " if (proj_)\n" + " return;\n" + " proj_ = new ProjectT(projPath);\n" + " proj_->open(new OpenCallback());\n" + " }\n" + "private:\n" + " static Core::ProjectBase* proj_;\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); } void missingAssignment() {