From f65bf6d565c6539730796b0dbfc3b89d2b693b6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 10 Jan 2010 14:00:32 +0100 Subject: [PATCH] Fixed #1220 (False memory leak when using while) --- lib/checkmemoryleak.cpp | 7 +++++++ test/testmemleak.cpp | 2 ++ 2 files changed, 9 insertions(+) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 0efc72a3b..f3314dc41 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1528,6 +1528,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all) done = false; } + // Reduce "{ loop ;" => ";" + if (Token::Match(tok2, "{ loop ;")) + { + tok2->deleteNext(); + done = false; + } + // Reduce "loop if break ; => ";" if (Token::Match(tok2->next(), "loop if break|continue ; !!else")) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index c348955eb..8a0798e4e 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -592,7 +592,9 @@ private: // switch.. ASSERT_EQUALS("; alloc ; dealloc ;", simplifycode(";alloc;switch{case;break;};dealloc;")); + ASSERT_EQUALS("; if return ; }", simplifycode("; switch { case ; return ; default ; break ; } }")); ASSERT_EQUALS("; if return ; else use ; }", simplifycode("; switch { case ; return ; default ; use ; break ; } }")); + ASSERT_EQUALS("; use ; }", simplifycode("; while1 { loop { ; } switch { case ; dealloc ; return ; default ; break ; } } }")); // loops.. ASSERT_EQUALS(";", simplifycode("; loop { break; }"));