From f28dec1f5a1eab27515d5e1cdd0ac65c6199395b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 21 Jun 2009 13:48:39 +0200 Subject: [PATCH] detect memory leak when all is given when calling an unknown function --- src/checkmemoryleak.cpp | 16 ++++++++++++++++ test/testmemleak.cpp | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index fd47650e4..6a792b56a 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -988,6 +988,22 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all) tok2 = tokEnd; } + // If "--all" is given, remove all "callfunc".. + if (_settings->_showAll) + { + Token *tok2 = tok; + while (tok2) + { + if (tok2->str() == "callfunc") + { + tok2->deleteThis(); + all = true; + } + else + tok2 = tok2->next(); + } + } + // reduce the code.. bool done = false; while (! done) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 7ce92577a..c81dbb358 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -254,6 +254,7 @@ private: TEST_CASE(unknownFunction1); TEST_CASE(unknownFunction2); TEST_CASE(unknownFunction3); + TEST_CASE(unknownFunction4); // VCL.. TEST_CASE(vcl1); @@ -1951,6 +1952,18 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str()); } + void unknownFunction4() + { + check("void foo()\n" + "{\n" + " int *p = new int[100];\n" + " a();\n" + " if (b) return;\n" + " delete [] p;\n" + "}\n", true); + ASSERT_EQUALS("[test.cpp:5]: (all) Memory leak: p\n", errout.str()); + } + void checkvcl(const char code[], const char _autoDealloc[])