diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 34a896af2..e0129af71 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1462,6 +1462,13 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) tok2->deleteNext(); } + // reduce "; callfunc ; %var%" + for (Token *tok2 = tok; tok2; tok2 = tok2->next()) + { + if (Token::Match(tok2, ";|{|} callfunc ; %type%")) + tok2->deleteNext(); + } + // remove redundant braces.. for (Token *start = tok; start; start = start->next()) { @@ -1561,13 +1568,6 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) done = false; } - // reduce "; callfunc ; %var%" - else if (Token::Match(tok2, "; callfunc ; %type%")) - { - tok2->deleteNext(); - done = false; - } - // Reduce "if if|callfunc" => "if" else if (Token::Match(tok2, "if if|callfunc")) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 23e9df322..f71cd1545 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -708,6 +708,7 @@ private: // callfunc.. ASSERT_EQUALS("; callfunc ;", simplifycode(";callfunc;")); + ASSERT_EQUALS("while1 { dealloc ; alloc ; } return ; }", simplifycode("while1 { dealloc ; alloc ; } callfunc ; return ; }")); // exit.. ASSERT_EQUALS("; exit ;", simplifycode("; alloc; exit;"));