Memory leak: Ensure that simple memory leak is detected

This commit is contained in:
Daniel Marjamäki 2008-11-09 17:27:23 +00:00
parent 8fce5d39e5
commit 2c74d1c0de
2 changed files with 22 additions and 0 deletions

View File

@ -181,6 +181,9 @@ static std::list<std::string> callstack;
static const char * call_func( const TOKEN *tok, const char *varnames[] )
{
if (Match(tok,"if") || Match(tok,"for") || Match(tok,"while"))
return 0;
if (GetAllocationType(tok)!=No || GetDeallocationType(tok,varnames)!=No)
return 0;

View File

@ -80,6 +80,8 @@ private:
TEST_CASE( ifelse8 );
TEST_CASE( ifelse9 );
TEST_CASE( if1 );
TEST_CASE( forwhile1 );
TEST_CASE( forwhile2 );
TEST_CASE( forwhile3 );
@ -368,6 +370,23 @@ private:
void if1()
{
check( "void f()\n"
"{\n"
" struct abc *p = new abc;\n"
" p->a = new char[100];\n"
" if ( ! p->a )\n"
" return;\n"
" foo(p);\n"
"}\n" );
ASSERT_EQUALS( std::string("[test.cpp:6]: Memory leak: p\n"), errout.str() );
}
void forwhile1()
{