diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index e6d3af291..cbb2a20ef 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -998,7 +998,9 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope) const Token* tok2 = tok->next()->astParent(); while (tok2 && tok2->isCast()) tok2 = tok2->astParent(); - if (Token::Match(tok2, "%assign%|return")) + if (Token::Match(tok2, "%assign%")) + continue; + if (Token::simpleMatch(tok->astTop(), "return")) continue; const std::string& functionName = tok->str(); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index e45b8a9d0..176482c7b 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2407,6 +2407,14 @@ private: ASSERT_EQUALS("[test.cpp:1]: (error) Allocation with new, if doesn't release it.\n" "[test.cpp:2]: (error) Allocation with malloc, if doesn't release it.\n", errout.str()); + + check("const char* string(const char* s) {\n" + " StringSet::iterator it = strings_.find(s);\n" + " if (it != strings_.end())\n" + " return *it;\n" + " return *strings_.insert(it, std::strcpy(new char[std::strlen(s) + 1], s));\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void missingAssignment() {