From 26a81e82ccade399372e98da9318262c64fc4afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 24 Oct 2009 15:07:14 +0200 Subject: [PATCH] Fixed #253 (MemoryLeakInClass: False positive when memory is released in function, which is called from destructor) --- src/checkmemoryleak.cpp | 15 +++++++++++---- test/testmemleak.cpp | 6 +++--- 2 files changed, 14 insertions(+), 7 deletions(-) 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()); } };