Memory leak: Better handling when calling functions

This commit is contained in:
Daniel Marjamäki 2008-11-21 18:02:20 +00:00
parent 7f4cc495df
commit a82b46dad6
2 changed files with 22 additions and 4 deletions

View File

@ -180,13 +180,13 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::list<const
return 0;
if ( callstack.size() > 2 )
return 0;
return "dealloc";
const char *funcname = tok->str;
for ( std::list<const TOKEN *>::const_iterator it = callstack.begin(); it != callstack.end(); ++it )
{
if ( std::string(funcname) == (*it)->str )
return 0;
return "dealloc";
}
callstack.push_back(tok);
@ -220,7 +220,7 @@ const char * CheckMemoryLeakClass::call_func( const TOKEN *tok, std::list<const
simplifycode( func );
const char *ret = 0;
if (Tokenizer::findmatch(func, "goto"))
ret = 0; // TODO : "goto" isn't handled well
ret = "dealloc"; // TODO : "goto" isn't handled well
else if (Tokenizer::findmatch(func, "use"))
ret = "use";
else if (Tokenizer::findmatch(func, "dealloc"))

View File

@ -112,6 +112,7 @@ private:
TEST_CASE( func3 );
TEST_CASE( func4 );
TEST_CASE( func5 );
TEST_CASE( func6 );
TEST_CASE( class1 );
TEST_CASE( class2 );
@ -746,6 +747,23 @@ private:
}
void func6()
{
check( "static void foo(char *str)\n"
"{\n"
" goto abc;\n"
"}\n"
"\n"
"static void f()\n"
"{\n"
" char *p = new char[100];\n"
" foo(p);\n"
"}\n" );
std::string err( errout.str() );
ASSERT_EQUALS( std::string(""), err );
}
/*
void func3()