From 5efedf85d6f55ce6fda4f5f8f13225bb49acbff6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 15 Sep 2009 22:26:38 +0200 Subject: [PATCH] Fixed #671 (False positive. Leak when loop is before exit) --- src/checkmemoryleak.cpp | 18 +++++++++++++----- test/testmemleak.cpp | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 0862433c2..bb7cb581c 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -1431,16 +1431,24 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok, bool &all) done = false; } - // Replace "loop ;" with ";" - if (Token::simpleMatch(tok2->next(), "loop ;")) + // Replace "do ; loop ;" with ";" + if (Token::Match(tok2->next(), "%any% ; loop ;")) { - Token::eraseTokens(tok2, tok2->tokAt(2)); + if (tok2->next()->str() == "do") + tok2->deleteNext(); + else + tok2 = tok2->next(); + Token::eraseTokens(tok2, tok2->tokAt(3)); done = false; } - // Replace "loop !var ;" with ";" - if (Token::Match(tok2->next(), "loop !var ;")) + // Replace "do ; loop !var ;" with ";" + if (Token::Match(tok2->next(), "%any% ; loop !var ;")) { + if (tok2->next()->str() == "do") + tok2->deleteNext(); + else + tok2 = tok2->next(); Token::eraseTokens(tok2, tok2->tokAt(4)); done = false; } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 74035b44e..db9d8a5d6 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -469,6 +469,7 @@ private: ASSERT_EQUALS(";", simplifycode("; loop { if { break; } }")); ASSERT_EQUALS("; loop alloc ;", simplifycode("; loop { alloc ; }")); ASSERT_EQUALS("; alloc ; alloc ;", simplifycode("; alloc ; do { alloc ; } loop ;")); + ASSERT_EQUALS("; exit ;", simplifycode("; alloc ; do { } loop ; exit ;")); // callfunc.. ASSERT_EQUALS("; callfunc ;", simplifycode(";callfunc;", false));