diff --git a/testmemleak1/err.msg b/testmemleak1/err.msg deleted file mode 100644 index 53c1cd3ce..000000000 --- a/testmemleak1/err.msg +++ /dev/null @@ -1 +0,0 @@ -Memory leak for 'clKalle::str' diff --git a/testmemleak1/testmemleak1.cpp b/testmemleak1/testmemleak1.cpp deleted file mode 100644 index 68fee5997..000000000 --- a/testmemleak1/testmemleak1.cpp +++ /dev/null @@ -1,23 +0,0 @@ - -class clKalle -{ -private: - char *str; - char *str2; -public: - clKalle(); - ~clKalle(); -}; - -clKalle::clKalle() -{ - str = new char[10]; - str2 = new char[10]; -} - -clKalle::~clKalle() -{ - delete [] str2; -} - - diff --git a/testmemleak2/err.msg b/testmemleak2/err.msg deleted file mode 100644 index d75f13a05..000000000 --- a/testmemleak2/err.msg +++ /dev/null @@ -1 +0,0 @@ -[testmemleak2\testmemleak2.cpp:8]: Memory leak:str diff --git a/testmemleak2/testmemleak2.cpp b/testmemleak2/testmemleak2.cpp deleted file mode 100644 index d4241aebc..000000000 --- a/testmemleak2/testmemleak2.cpp +++ /dev/null @@ -1,12 +0,0 @@ - - -bool f() -{ - char *str = strdup("hello"); - if (a==b) - { - return false; - } - free(str); - return true; -} diff --git a/testmemleak3/err.msg b/testmemleak3/err.msg deleted file mode 100644 index 61aa2037b..000000000 --- a/testmemleak3/err.msg +++ /dev/null @@ -1 +0,0 @@ -[testmemleak3\testmemleak3.cpp:11]: Memory leak:str diff --git a/testmemleak3/testmemleak3.cpp b/testmemleak3/testmemleak3.cpp deleted file mode 100644 index dd1543909..000000000 --- a/testmemleak3/testmemleak3.cpp +++ /dev/null @@ -1,12 +0,0 @@ - - -bool f() -{ - char *str = strdup("hello"); - if (a==b) - { - free(str); - return false; - } - return true; -} diff --git a/testmemleak4/err.msg b/testmemleak4/err.msg deleted file mode 100644 index e69de29bb..000000000 diff --git a/testmemleak4/testmemleak4.cpp b/testmemleak4/testmemleak4.cpp deleted file mode 100644 index 7bff9bd1a..000000000 --- a/testmemleak4/testmemleak4.cpp +++ /dev/null @@ -1,15 +0,0 @@ - -bool f() -{ - TStringList *StringList = new TStringList; - - if (asd) - { - delete StringList; - return false; - } - - delete StringList; - return true; -} - diff --git a/tests.cpp b/tests.cpp index 7e94ad9bd..532e97cba 100644 --- a/tests.cpp +++ b/tests.cpp @@ -25,6 +25,7 @@ static void constructors(); static void operator_eq(); static void mismatching_allocation_deallocation(); static void memleak_in_function(); +static void memleak_in_class(); //--------------------------------------------------------------------------- int main() @@ -35,6 +36,7 @@ int main() operator_eq(); memleak_in_function(); mismatching_allocation_deallocation(); + memleak_in_class(); std::cout << "Success Rate: " << SuccessCount << " / " @@ -268,6 +270,7 @@ static void memleak_in_function() // test3: check all execution paths // test4: check all execution paths // test5: check all execution paths + // test6: check all execution paths const char test1[] = "void f()\n" "{\n" @@ -324,7 +327,7 @@ static void memleak_in_function() const char test5[] = "void f()\n" "{\n" - " char *str = strdup(\"hello\");\n" + " char *str = strdup(\"hello\");\n" " while (condition)\n" " {\n" " if (condition)\n" @@ -334,6 +337,82 @@ static void memleak_in_function() "}\n"; check( CheckMemoryLeak, __LINE__, test5, "" ); + + + + const char test6[] = "void f()\n" + "{\n" + " char *str = strdup(\"hello\");\n" + " if (a==b)\n" + " {\n" + " return;\n" + " }\n" + " free(str);\n" + "}\n"; + check( CheckMemoryLeak, __LINE__, test6, "[test.cpp:6]: Memory leak:str\n" ); + + + + + const char test7[] = "void f()\n" + "{\n" + " char *str = strdup(\"hello\");\n" + " if (a==b)\n" + " {\n" + " free(str);\n" + " return;\n" + " }\n" + "}\n"; + check( CheckMemoryLeak, __LINE__, test7, "[test.cpp:9]: Memory leak:str\n" ); + + + + + const char test8[] = "void f()\n" + "{\n" + " char *str = new char[10];\n" + " if (a==b)\n" + " {\n" + " delete [] str;\n" + " return;\n" + " }\n" + " delete [] str;\n" + "}\n"; + check( CheckMemoryLeak, __LINE__, test8, "" ); + +} +//--------------------------------------------------------------------------- + +static void memleak_in_class() +{ + + + const char test1[] = "class clKalle\n" + "{\n" + "private:\n" + " char *str1;\n" + " char *str2;\n" + "public:\n" + " clKalle();\n" + " ~clKalle();\n" + "};\n" + "\n" + "clKalle::clKalle()\n" + "{\n" + " str1 = new char[10];\n" + " str2 = new char[10];\n" + "}\n" + "\n" + "clKalle::~clKalle()\n" + "{\n" + " delete [] str2;\n" + "}\n"; + + check( CheckMemoryLeak, __LINE__, test1, "Memory leak for 'clKalle::str1'\n" ); + + + + } //---------------------------------------------------------------------------