diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 106f53902..8944744ab 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -464,6 +464,9 @@ const char *CheckMemoryLeak::functionArgAlloc(const Function *func, unsigned int if (!func || !func->functionScope) return ""; + if (!Token::simpleMatch(func->retDef, "void")) + return ""; + std::list::const_iterator arg = func->argumentList.begin(); for (; arg != func->argumentList.end(); ++arg) { if (arg->index() == targetpar-1) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index d07b413d9..514ffd411 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2666,6 +2666,20 @@ private: " free(tmp);\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("int alloc(char **str) {\n" + " *str = malloc(20);\n" + " if (condition) { free(str); return -123; }\n" + " return 0;\n" + "}\n" + "\n" + "void bar()\n" + "{\n" + " char *p;\n" + " if ((ret = alloc(&p)) != 0) return;\n" + " free(p);\n" + "}"); + ASSERT_EQUALS(std::string(""), errout.str()); }