From e1b54df368f157011a90f3b9d2f4d4c1508432ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 6 Feb 2010 22:35:36 +0100 Subject: [PATCH] Fixed #1346 (False positive: Memory leak when allocated memory is stored elsewhere inside a condition) --- lib/checkmemoryleak.cpp | 2 +- test/testmemleak.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 3958d1de8..aa1883ee7 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -639,7 +639,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::liststr() != "{")) ftok = ftok->next(); Token *func = getcode(ftok->tokAt(1), callstack, parameterVarid, alloctype, dealloctype, false, all, sz); - simplifycode(func, all); + //simplifycode(func, all); const Token *func_ = func; while (func_ && func_->str() == ";") func_ = func_->next(); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 7b4f2a858..2d8f3e41a 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -295,6 +295,7 @@ private: TEST_CASE(func14); TEST_CASE(func15); TEST_CASE(func16); + TEST_CASE(func17); TEST_CASE(allocfunc1); TEST_CASE(allocfunc2); @@ -1580,6 +1581,32 @@ private: } + void func17() + { + // The "bar" function must be reduced to "use" + + check("bool bar(char **parent, char *res, bool a)\n" + "{\n" + " if( a )\n" + " {\n" + " *parent = res;\n" + " return false;\n" + " }\n" + " return true;\n" + "}\n" + "\n" + "void foo(char **parent, bool a)\n" + "{\n" + " if (a)\n" + " {\n" + " char *res = malloc(65);\n" + " bar(parent, res, a);\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + + void allocfunc1() {