Memory leak: Better handling when calling functions
This commit is contained in:
parent
7f4cc495df
commit
a82b46dad6
|
@ -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"))
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue