From 80069f016e23134aa5aa36017ee79081bbbe4f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 27 Sep 2010 17:53:10 +0200 Subject: [PATCH] Fixed #2065 (false positive: memory leak) --- lib/checkmemoryleak.cpp | 4 ++-- test/testmemleak.cpp | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index b120d7cde..7f04bf744 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -2134,9 +2134,9 @@ const Token *CheckMemoryLeakInFunction::findleak(const Token *tokens) return result->tokAt(2); } - if ((result = Token::findmatch(tokens, "alloc ; if assign ;")) != NULL) + if ((result = Token::findmatch(tokens, "; alloc ; if assign ;")) != NULL) { - return result->tokAt(3); + return result->tokAt(4); } if (((result = Token::findmatch(tokens, "; alloc ; if dealloc ; }")) != NULL) && diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index fe8968020..e87756783 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -812,6 +812,7 @@ private: ASSERT_EQUALS(2, dofindleak("if alloc;\n return;")); ASSERT_EQUALS(notfound, dofindleak("if alloc;\n return use;")); ASSERT_EQUALS(notfound, dofindleak("if alloc;\n use;")); + ASSERT_EQUALS(notfound, dofindleak("if alloc;\n if assign;\n if dealloc; }")); // if.. ASSERT_EQUALS(notfound, dofindleak("alloc; ifv dealloc;")); @@ -832,7 +833,7 @@ private: // assign.. ASSERT_EQUALS(2, dofindleak("alloc;\n assign;\n dealloc;")); ASSERT_EQUALS(notfound, dofindleak("alloc;\n if(!var) assign;\n dealloc;")); - ASSERT_EQUALS(2, dofindleak("alloc;\n if assign;\n dealloc;")); + ASSERT_EQUALS(2, dofindleak(";alloc;\n if assign;\n dealloc;")); // loop.. TODO_ASSERT_EQUALS(1, dofindleak("; loop { alloc ; if break; dealloc ; }"));