From a6c9a6fc54410dcc7311a744d6f77b939dbbb60d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 20 Feb 2010 10:17:45 +0100 Subject: [PATCH] Fixed #1407 (false positive memory leak when returning pointer to the allocated memory) --- lib/checkmemoryleak.cpp | 4 ++-- test/testmemleak.cpp | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index ceecacdf5..ded89267d 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1586,9 +1586,9 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all) } // Reduce "alloc|dealloc|use|callfunc ; exit ;" => "; exit ;" - if (Token::Match(tok2, "alloc|dealloc|use|callfunc ; exit ;")) + if (Token::Match(tok2, "[;{}] alloc|dealloc|use|callfunc ; exit ;")) { - tok2->deleteThis(); + tok2->deleteNext(); done = false; } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 2d8f3e41a..f42fa21f6 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -665,6 +665,9 @@ private: ASSERT_EQUALS("; alloc ; return ;", simplifycode(";alloc;if{return;}return;")); ASSERT_EQUALS("; alloc ; assign ; dealloc ;", simplifycode(";alloc;if{assign;}dealloc;")); + // if(var) + ASSERT_EQUALS("; alloc ; return use ;", simplifycode("; alloc ; return use ;")); + // switch.. ASSERT_EQUALS("; alloc ; dealloc ;", simplifycode(";alloc;switch{case;break;};dealloc;")); ASSERT_EQUALS("; if return ;", simplifycode("; switch { case ; return ; default ; break ; }"));