From 5570f0607548b17770680d66d636a64d7e328e0e Mon Sep 17 00:00:00 2001 From: Leandro Penz Date: Sat, 10 Jan 2009 16:28:04 +0000 Subject: [PATCH] checkmemoryleak: no longer flag "dealloc ; alloc ; if continue ;" as a leak, even with --all --- src/checkmemoryleak.cpp | 3 ++- test/testmemleak.cpp | 44 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 9ac022355..d7dfa6f62 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -1172,7 +1172,8 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope(const Token *Tok1, const c MemoryLeak(result, varname, alloctype); } - else if ((result = Token::findmatch(tok, "alloc ; if break|continue|return ;")) != NULL) + else if ((result = Token::findmatch(tok, "alloc ; if break|continue|return ;")) != NULL + && Token::findmatch(tok, "dealloc ; alloc ; if continue ;") == NULL) { MemoryLeak(result->tokAt(3), varname, alloctype); } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 52e88bb1e..6430200ab 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -102,6 +102,8 @@ private: TEST_CASE(forwhile6); TEST_CASE(forwhile7); TEST_CASE(forwhile8); // Bug 2429936 + TEST_CASE(forwhile9); + TEST_CASE(forwhile10); TEST_CASE(dowhile1); @@ -749,6 +751,48 @@ private: } + void forwhile9() + { + check("char *f()\n" + "{\n" + " char *a = 0;\n" + " int i = 0;\n" + " for( ;; )\n" + " {\n" + " if(i>=0)\n" + " continue;\n" + " a = realloc( a, i );\n" + " if(i>=0)\n" + " continue;\n" + " }\n" + "\n" + " return a;\n" + "}\n", true); + ASSERT_EQUALS(std::string(""), errout.str()); + } + + + void forwhile10() + { + check("char *f()\n" + "{\n" + " char *a = 0;\n" + " int i = 0;\n" + " for( ;; )\n" + " {\n" + " if(i>=0)\n" + " continue;\n" + " a = realloc( a, i );\n" + " if(i>=0)\n" + " return;\n" + " }\n" + "\n" + " return a;\n" + "}\n", true); + ASSERT_EQUALS(std::string("[test.cpp:11]: Memory leak: a\n"), errout.str()); + } + +