Memory leak : fixed false positive when there are recursive calls. (using memory after it has been freed)

This commit is contained in:
Daniel Marjamäki 2009-01-01 11:02:30 +00:00
parent 0b69a13205
commit b7b737c8f2
2 changed files with 14 additions and 1 deletions

View File

@ -219,7 +219,7 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::list<const
for ( std::list<const TOKEN *>::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 );

View File

@ -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() );
}
};