Test Memory leak: Added a test case, currently a false positive is generated

This commit is contained in:
Daniel Marjamäki 2008-11-29 16:42:14 +00:00
parent 87794cc66c
commit 8c07a13cb6
1 changed files with 25 additions and 14 deletions

View File

@ -112,7 +112,8 @@ private:
TEST_CASE( func4 );
TEST_CASE( func5 );
TEST_CASE( func6 );
// TODO TEST_CASE( func7 );
// TODO TEST_CASE( func7 );
// TEST_CASE( func8 ); // Using callback
// TODO TEST_CASE( class1 );
// TODO TEST_CASE( class2 );
@ -786,24 +787,34 @@ private:
void func7()
{
check( "static void foo(char *str)\n"
check( "static void foo(char *str)\n"
"{\n"
" if (abc)\n"
" return;"
" delete [] str;\n"
"}\n"
"\n"
"static void f()\n"
"{\n"
" char *p = new char[100];\n"
" foo(p);\n"
"}\n" );
" return;"
" delete [] str;\n"
"}\n"
"\n"
"static void f()\n"
"{\n"
" char *p = new char[100];\n"
" foo(p);\n"
"}\n" );
std::string err( errout.str() );
std::cout << err << "\n";
ASSERT_EQUALS( std::string("[test.cpp:11]: Memory leak: p\n"), err );
ASSERT_EQUALS( std::string("[test.cpp:11]: Memory leak: p\n"), err );
}
void func8()
{
check( "static void foo()\n"
"{\n"
" char *str = new char[100];"
" (*release)(str);\n"
"}\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}
/*
void func3()