diff --git a/checkmemoryleak.cpp b/checkmemoryleak.cpp index 7b1354cae..f67c5055b 100644 --- a/checkmemoryleak.cpp +++ b/checkmemoryleak.cpp @@ -219,7 +219,7 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::list::const_iterator it = callstack.begin(); it != callstack.end(); ++it ) { if ( (*it)->str() == funcname ) - return "dealloc"; + return "recursive"; } callstack.push_back(tok); @@ -1102,6 +1102,8 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const tok2->str("use"); else if (tok2->str() == "&use2") tok2->str(";"); + else if (tok2->str() == "recursive") + tok2->str("dealloc"); } simplifycode( tok ); diff --git a/testmemleak.cpp b/testmemleak.cpp index 425004e70..c19ddb39e 100644 --- a/testmemleak.cpp +++ b/testmemleak.cpp @@ -155,6 +155,7 @@ private: TEST_CASE( dealloc_use_1 ); // Deallocate and then use memory TEST_CASE( dealloc_use_2 ); // Deallocate and then use memory. No error if "use" is &var TEST_CASE( dealloc_use_3 ); // Deallocate and then use memory. No error + TEST_CASE( dealloc_use_4 ); } @@ -1402,6 +1403,16 @@ private: ASSERT_EQUALS( std::string(""), errout.str() ); } + void dealloc_use_4() + { + check( "static void ReadDir(DIR *d)\n" + "{\n" + " DIR *subdir = OpenDir();\n" + " ReadDir( subdir );\n" + " closedir(subdir);\n" + "}\n" ); + ASSERT_EQUALS( std::string(""), errout.str() ); + } };