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() {