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