From f4319a865f0a5429b528063598aab15227a10563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 19 Oct 2008 07:23:06 +0000 Subject: [PATCH] Memory Leak: Fixed false positive --- CheckMemoryLeak.cpp | 4 ++-- testmemleak.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index cf389bfec..56cf12f00 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -454,10 +454,10 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[] done = false; } - // Delete "loop ;" + // Replace "loop ;" with ";" if ( Match(tok2->next, "loop ;") ) { - erase(tok2, gettok(tok2,3)); + erase(tok2, gettok(tok2,2)); done = false; } diff --git a/testmemleak.cpp b/testmemleak.cpp index 45830dd02..fda0d082e 100644 --- a/testmemleak.cpp +++ b/testmemleak.cpp @@ -40,6 +40,7 @@ private: TEST_CASE( simple5 ); TEST_CASE( simple6 ); TEST_CASE( simple7 ); + TEST_CASE( simple8 ); TEST_CASE( ifelse1 ); TEST_CASE( ifelse2 ); @@ -140,6 +141,20 @@ private: } + void simple8() + { + check( "char * foo ()\n" + "{\n" + " char *str = strdup(\"abc\");\n" + " if (somecondition)\n" + " for (i = 0; i < 2; i++)\n" + " { }\n" + " return str;\n" + "}\n" ); + ASSERT_EQUALS( std::string(""), errout.str() ); + } + +