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 ; }"));