From 8e746ca53f42379bc7e38284c8c4f84b2410cf85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 8 Sep 2010 19:22:03 +0200 Subject: [PATCH] CheckMemoryleaks: reduce 'use ; if return ; dealloc ;' to 'if return ; dealloc ;'. ticket: #2037 --- lib/checkmemoryleak.cpp | 11 +++++++++-- test/testmemleak.cpp | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 7afb526f0..67a17fb9d 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1915,17 +1915,24 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) done = false; } - // Delete first part in "use ; dealloc ;" + // use; dealloc; => dealloc; if (Token::Match(tok2, "[;{}] use ; dealloc ;")) { Token::eraseTokens(tok2, tok2->tokAt(3)); done = false; } + // use; if return; dealloc; => if return; dealloc; + if (Token::Match(tok2, "[;{}] use ; if return ; dealloc ;")) + { + Token::eraseTokens(tok2, tok2->tokAt(3)); + done = false; + } + // Delete first part in "use ; return use ;" if (Token::Match(tok2, "[;{}] use ; return use ;")) { - Token::eraseTokens(tok2, tok2->tokAt(2)); + Token::eraseTokens(tok2, tok2->tokAt(3)); done = false; } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 0fa69c68c..e04e527f0 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -735,6 +735,9 @@ private: // dealloc; dealloc; ASSERT_EQUALS("; alloc ; if dealloc ; dealloc ;", simplifycode("; alloc ; if { dealloc ; } dealloc ;")); + + // use ; dealloc ; + ASSERT_EQUALS("; alloc ; if return ; dealloc ;", simplifycode("; alloc ; use ; if { return ; } dealloc ;")); }