From ad92aa4c20230fbc8503661ee95adc74b1be1011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 22 Sep 2009 18:09:29 +0200 Subject: [PATCH] Fixed #715 (False positive: Resource leak when exit() after if loop) --- src/checkmemoryleak.cpp | 10 +++++++++- test/testmemleak.cpp | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index beb5ab82a..782c5f141 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -1352,13 +1352,21 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all) done = false; } - // Reduce "alloc|dealloc|use ; exit ;" => "; exit ;" + // Reduce "alloc|dealloc|use|callfunc ; exit ;" => "; exit ;" if (Token::Match(tok2, "alloc|dealloc|use|callfunc ; exit ;")) { tok2->deleteThis(); done = false; } + // Reduce "if loop ; exit ;" => "; exit ;" + if (Token::Match(tok2, "if loop ; exit ;")) + { + tok2->deleteThis(); + tok2->deleteThis(); + done = false; + } + // Reduce "alloc|dealloc|use ; if(var) exit ;" if (Token::Match(tok2, "alloc|dealloc|use ; if(var) exit ;")) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index bcb7abaad..0b3763028 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -490,6 +490,7 @@ private: // exit.. ASSERT_EQUALS("; exit ;", simplifycode("; alloc; exit;")); + ASSERT_EQUALS("; exit ;", simplifycode("; alloc; if { loop ; } dealloc; exit;")); ASSERT_EQUALS(";", simplifycode("; if { alloc; exit; }")); ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; if { use; exit; }")); ASSERT_EQUALS("; alloc ;", simplifycode("; alloc ; if(!var) { exit; }"));