diff --git a/testmemleak.cpp b/testmemleak.cpp index 318eaec20..ee5d9503f 100644 --- a/testmemleak.cpp +++ b/testmemleak.cpp @@ -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 )