Memory leak : Added a test case for future checking of struct members

This commit is contained in:
Daniel Marjamäki 2008-12-16 19:16:52 +00:00
parent b145bf3650
commit fc325ac98a
1 changed files with 60 additions and 40 deletions

View File

@ -85,7 +85,7 @@ private:
TEST_CASE( if2 );
TEST_CASE( if3 );
TEST_CASE( if4 );
TEST_CASE( if5 );
TEST_CASE( if5 );
TEST_CASE( if6 ); // Bug 2432631
TEST_CASE( alwaysTrue );
@ -96,7 +96,7 @@ private:
TEST_CASE( forwhile4 );
TEST_CASE( forwhile5 );
TEST_CASE( forwhile6 );
TEST_CASE( forwhile7 );
TEST_CASE( forwhile7 );
TEST_CASE( forwhile8 ); // Bug 2429936
TEST_CASE( dowhile1 );
@ -140,6 +140,9 @@ private:
TEST_CASE( cast1 );
TEST_CASE( cast2 );
TEST_CASE( cast3 );
// TODO TEST_CASE( structmember1 );
}
@ -471,22 +474,22 @@ private:
"}\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}
void if6()
{
check( "void f()\n"
"{\n"
" FILE *a = 0;\n"
" a = fopen(\"test.txt\", \"rw\");\n"
" if( a == 0 )\n"
" {\n"
" a = fopen(\"test.txt\", \"r\");\n"
" }\n"
"\n"
" fclose( a );\n"
"}\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}
void if6()
{
check( "void f()\n"
"{\n"
" FILE *a = 0;\n"
" a = fopen(\"test.txt\", \"rw\");\n"
" if( a == 0 )\n"
" {\n"
" a = fopen(\"test.txt\", \"r\");\n"
" }\n"
"\n"
" fclose( a );\n"
"}\n" );
ASSERT_EQUALS( std::string(""), errout.str() );
}
@ -621,29 +624,29 @@ private:
"}\n");
ASSERT_EQUALS( std::string("[test.cpp:7]: Memory leak: str\n"), errout.str() );
}
void forwhile8()
{
check("char *f()\n"
"{\n"
" char *a = 0;\n"
" int i = 0;\n"
" for( ;; )\n"
" {\n"
" i++;\n"
" a = realloc( a, i );\n"
" if( !a )\n"
" return 0;\n"
"\n"
" if( i > 10 )\n"
" break;\n"
" }\n"
"\n"
" return a;\n"
void forwhile8()
{
check("char *f()\n"
"{\n"
" char *a = 0;\n"
" int i = 0;\n"
" for( ;; )\n"
" {\n"
" i++;\n"
" a = realloc( a, i );\n"
" if( !a )\n"
" return 0;\n"
"\n"
" if( i > 10 )\n"
" break;\n"
" }\n"
"\n"
" return a;\n"
"}\n");
ASSERT_EQUALS( std::string(""), errout.str() );
}
ASSERT_EQUALS( std::string(""), errout.str() );
}
@ -1162,6 +1165,23 @@ private:
ASSERT_EQUALS( std::string(""), errout.str() );
}
void structmember1()
{
check( "void f()\n"
"{\n"
" struct ABC *abc = new ABC;\n"
" abc->a = new char[100];\n"
" delete abc;\n"
"}\n" );
ASSERT_EQUALS( std::string("[test.cpp:5]: Memory leak: abc.a\n"), errout.str() );
}
};
REGISTER_TEST( TestMemleak )