diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index c7cc629fa..34a896af2 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -2032,21 +2032,9 @@ const Token *CheckMemoryLeakInFunction::findleak(const Token *tokens) while (last->next()) last = last->next(); - // check if we call exit before the end of the funcion - Token *tok2 = last->previous(); - if (tok2) - { - if (Token::simpleMatch(tok2, ";")) - { - const Token *tok3 = tok2->previous(); - if (tok3 && Token::simpleMatch(tok3, "exit")) - { - return NULL; - } - } - } - - return last; + // not a leak if exit is called before the end of the funcion + if (!Token::Match(last->tokAt(-2), "exit|callfunc ; }")) + return last; } return NULL; diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 22a25ff3a..23e9df322 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -356,7 +356,6 @@ private: // Calls to unknown functions.. they may throw exception, quit the program, etc TEST_CASE(unknownFunction1); TEST_CASE(unknownFunction2); - TEST_CASE(unknownFunction3); TEST_CASE(unknownFunction4); TEST_CASE(unknownFunction5); @@ -805,6 +804,9 @@ private: ASSERT_EQUALS(notfound, dofindleak("; loop { alloc ; if break; } dealloc ;")); ASSERT_EQUALS(1, dofindleak("; loop alloc ;")); ASSERT_EQUALS(1, dofindleak("; loop alloc ; dealloc ;")); + + // callfunc (might be noreturn) + ASSERT_EQUALS(notfound, dofindleak("; alloc ; callfunc ; }")); } @@ -2296,16 +2298,6 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: p\n", errout.str()); } - void unknownFunction3() - { - check("void foo()\n" - "{\n" - " int *p = new int[100];\n" - " ThrowException();\n" - "}\n"); - ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str()); - } - void unknownFunction4() { check("void foo()\n"