From 9e348ca7396712ccb308df65405b7602443b4839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 4 Aug 2009 21:34:14 +0200 Subject: [PATCH] Fixed #554 (resource leak false positive) --- src/checkmemoryleak.cpp | 2 +- test/testmemleak.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index a0e653819..ee9c68401 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -1241,7 +1241,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all) } // Reduce "alloc|dealloc|use ; exit ;" => "; exit ;" - if (Token::Match(tok2, "alloc|dealloc|use ; exit ;")) + if (Token::Match(tok2, "alloc|dealloc|use|callfunc ; exit ;")) { tok2->deleteThis(); done = false; diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 21312be2b..818154277 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -266,6 +266,7 @@ private: TEST_CASE(exit2); TEST_CASE(exit3); TEST_CASE(exit4); + TEST_CASE(exit5); TEST_CASE(stdstring); TEST_CASE(strndup_function); @@ -2164,6 +2165,20 @@ private: ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: p\n", errout.str()); } + void exit5() + { + check("void f()\n" + "{\n" + " char *p = malloc(100);\n" + " if (p)\n" + " {\n" + " xyz();\n" + " exit(0);\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void stdstring()