Memory Leak: Added checking

This commit is contained in:
Daniel Marjamäki 2008-11-07 17:24:19 +00:00
parent 789aac2ef4
commit 7569071846
2 changed files with 21 additions and 6 deletions

View File

@ -52,7 +52,7 @@ static bool isclass( const std::string &typestr )
return false; return false;
std::ostringstream pattern; std::ostringstream pattern;
pattern << "struct " << typestr << " [;{]"; pattern << "struct " << typestr;
if ( findmatch( tokens, pattern.str().c_str() ) ) if ( findmatch( tokens, pattern.str().c_str() ) )
return false; return false;
@ -203,12 +203,12 @@ static void instoken(TOKEN *tok, const char str[])
static bool notvar(const TOKEN *tok, const char *varnames[]) static bool notvar(const TOKEN *tok, const char *varnames[])
{ {
return bool( Match(tok, "! %var1%", varnames) || return bool( Match(tok, "! %var1% [;)&|]", varnames) ||
Match(tok, "unlikely ( ! %var1% )", varnames) || Match(tok, "unlikely ( ! %var1% )", varnames) ||
Match(tok, "unlikely ( %var1% == NULL )", varnames) || Match(tok, "unlikely ( %var1% == NULL )", varnames) ||
Match(tok, "%var1% == NULL", varnames) || Match(tok, "%var1% == NULL", varnames) ||
Match(tok, "NULL == %var1%", varnames) || Match(tok, "NULL == %var1% [;)&|]", varnames) ||
Match(tok, "%var1% == 0", varnames) ); (!Match(tok,".") && Match(tok->next, "%var1% == 0", varnames)) );
} }

View File

@ -82,7 +82,8 @@ private:
TEST_CASE( switch1 ); TEST_CASE( switch1 );
TEST_CASE( switch2 ); TEST_CASE( switch2 );
TEST_CASE( ret ); TEST_CASE( ret1 );
TEST_CASE( ret2 );
TEST_CASE( mismatch1 ); TEST_CASE( mismatch1 );
@ -463,7 +464,7 @@ private:
void ret() void ret1()
{ {
check( "char *f( char **str )\n" check( "char *f( char **str )\n"
"{\n" "{\n"
@ -475,6 +476,20 @@ private:
} }
void ret2()
{
check( "void foo()\n"
"{\n"
" struct ABC *abc = new ABC;\n"
" abc->a = new char[10];\n"
" if ( ! abc->a )\n"
" return;\n"
" delete [] abc->a;\n"
" delete abc;\n"
"}\n" );
ASSERT_EQUALS( std::string("[test.cpp:6]: Memory leak: abc\n"), errout.str() );
}