diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 3c7a56875..079bcfd8d 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -2155,10 +2155,6 @@ void CheckMemoryLeakInClass::variable(const char classname[], const Token *tokVa if (indent == 0) continue; - // Function call in destructor.. possible deallocation - if (destructor && Token::Match(tok, "[{};] %var% (")) - deallocInDestructor = true; - // Deallocate.. const char *varnames[3] = { "var", 0, 0 }; varnames[0] = varname; @@ -2187,6 +2183,17 @@ void CheckMemoryLeakInClass::variable(const char classname[], const Token *tokVa Dealloc = dealloc; } + + // Function call in destructor .. possible deallocation + else if (destructor && Token::Match(tok->previous(), "[{};] %var% (")) + { + if (!std::bsearch(tok->strAt(0), call_func_white_list, + sizeof(call_func_white_list) / sizeof(call_func_white_list[0]), + sizeof(call_func_white_list[0]), call_func_white_list_compare)) + { + return; + } + } } } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index f54c4ea92..546665fb1 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2564,7 +2564,7 @@ private: " }\n" "}\n", true); - TODO_ASSERT_EQUALS("", errout.str()); + ASSERT_EQUALS("", errout.str()); } void class4() @@ -2799,7 +2799,7 @@ private: "{\n" " delete tok;\n" "}\n", true); - TODO_ASSERT_EQUALS("", errout.str()); + ASSERT_EQUALS("", errout.str()); // Global function check("void deleteTokens(int *tok)\n" @@ -2826,7 +2826,7 @@ private: " deleteTokens(_tokens);\n" " _tokens = 0;\n" "}\n", true); - TODO_ASSERT_EQUALS("", errout.str()); + ASSERT_EQUALS("", errout.str()); } };