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 ; }"));