From df44703ee914ef0dcb67e3e03233b10d623ecc99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 2 Aug 2010 21:56:50 +0200 Subject: [PATCH] memory leaks: better checking of function calls. If there are statements after the function call it is unlikely the function call is noreturn --- lib/checkmemoryleak.cpp | 14 +++++++------- test/testmemleak.cpp | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) 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;"));