diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 7876256d2..d3f402bd3 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -386,6 +386,9 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* f if (Token::Match(tok, "[(,] & %varid% [.,)]", varid)) { return No; } + if (Token::Match(tok, "[;{}] %varid% .", varid)) { + return No; + } if (allocType == No && tok->str() == "return") return No; } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index aac5f5c4d..0d09d6d7d 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2575,6 +2575,20 @@ private: " char* s = data();\n" "}"); ASSERT_EQUALS("", errout.str()); + + // #5144 + check("C* BuildC( C *previous ) {\n" + " C *result = malloc(100);\n" + " result->previous = previous;\n" + " return result;\n" + "}\n" + "C *ParseC( ) {\n" + " C *expr1 = NULL;\n" + " while( something() )\n" + " expr1 = BuildC(expr1);\n" + " return expr1;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void allocfunc8() {