From 8715ba14586e19ad2a5401d9e3d7202fc073fa67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 21 Jun 2009 14:12:59 +0200 Subject: [PATCH] CheckMemoryLeakInFunction: More sensitive checking when the code calls an unknown function --- src/checkmemoryleak.cpp | 8 ++++++++ test/testmemleak.cpp | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 6a792b56a..1d113ea3e 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -1353,6 +1353,14 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all) done = false; } + // Delete "callfunc ;" that is followed by "use|if|callfunc" + // If the function doesn't throw exception or exit the application, then the "callfunc" is not needed + if (Token::Match(tok2, "callfunc ; use|if|callfunc")) + { + tok2->deleteThis(); + done = false; + } + // Delete second case in "case ; case ;" while (Token::simpleMatch(tok2, "case ; case ;")) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index c81dbb358..7f0855283 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -1960,8 +1960,8 @@ private: " a();\n" " if (b) return;\n" " delete [] p;\n" - "}\n", true); - ASSERT_EQUALS("[test.cpp:5]: (all) Memory leak: p\n", errout.str()); + "}\n"); + ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str()); }