diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 5fe8aaa8a..06324799a 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -363,6 +363,8 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* f for (const Token *tok2 = func->functionScope->bodyStart; tok2 != func->functionScope->bodyEnd; tok2 = tok2->next()) { if (const Token *endOfLambda = findLambdaEndToken(tok2)) tok2 = endOfLambda; + if (tok2->str() == "{" && !tok2->scope()->isExecutable()) + tok2 = tok2->link(); if (tok2->str() == "return") { const AllocType allocType = getAllocationType(tok2->next(), 0, callstack); if (allocType != No) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index e5160f678..c2f5b2394 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -1928,6 +1928,15 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + check("void *f() {\n" // #8848 + " struct S { void *alloc() { return malloc(10); } };\n" + "}\n" + "void x()\n" + "{\n" + " f();\n" + "}"); + ASSERT_EQUALS("", errout.str()); + check("void x()\n" "{\n" " if(!malloc(5)) fail();\n"