From 5fc2a55bac1e788f9fc4bbb4f33a487f495505a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 2 Aug 2011 09:04:13 +0200 Subject: [PATCH] Fixed #2900 (found memory leak in kernel p54usb and a false positive reported) --- lib/checkmemoryleak.cpp | 5 +++-- test/testmemleak.cpp | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 3d46ee4e3..ca6471d0d 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1915,8 +1915,9 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) done = false; } - // Remove "if { dealloc ; callfunc ; } !!else" - else if (Token::Match(tok2->next(), "if { dealloc|assign ; callfunc ; } !!else")) + // Remove "if { dealloc ; callfunc ; } !!else|return" + else if (Token::Match(tok2->next(), "if { dealloc|assign ; callfunc ; }") && + !Token::Match(tok2->tokAt(8), "else|return")) { Token::eraseTokens(tok2, tok2->tokAt(8)); done = false; diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 63321a733..2b87d7f15 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -738,6 +738,10 @@ private: ASSERT_EQUALS("dealloc ; alloc ; return ; }", simplifycode("while1 { dealloc ; alloc ; } callfunc ; return ; }")); ASSERT_EQUALS("; }", simplifycode("loop callfunc ; }")); + // #2900 - don't report false positive + ASSERT_EQUALS("; alloc ; if { if { dealloc ; callfunc ; } return ; } dealloc ; }", + simplifycode("; alloc ; if { if { dealloc ; callfunc ; } return ; } dealloc ; }")); + // exit.. ASSERT_EQUALS("; exit ;", simplifycode("; alloc; exit;")); ASSERT_EQUALS("; exit ;", simplifycode("; alloc; if { loop ; } dealloc; exit;"));