From f94243f85e9a44da561ac5a71a709b4c92b37d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 4 Jan 2015 11:46:26 +0100 Subject: [PATCH] CheckMemoryLeak: Fix fp for allocation function that returns success value --- lib/checkmemoryleak.cpp | 3 +++ test/testmemleak.cpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+) 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()); }