Memory leak: Ensure that simple memory leak is detected
This commit is contained in:
parent
8fce5d39e5
commit
2c74d1c0de
|
@ -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;
|
||||
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue