diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index d45294452..0c54f7ef8 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -2389,6 +2389,9 @@ void CheckMemoryLeakInClass::parseClass(const Token *tok1, std::vectorinconclusive) + return; + const std::string varname = tokVarname->strAt(0); // Check if member variable has been allocated and deallocated.. diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 4a3592cad..baf2e8ea0 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2849,6 +2849,7 @@ private: TEST_CASE(class13); TEST_CASE(class14); TEST_CASE(class15); + TEST_CASE(class16); TEST_CASE(staticvar); @@ -2884,8 +2885,8 @@ private: "{\n" " delete [] str2;\n" "}\n"); - - ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: Fred::str1\n", errout.str()); + ASSERT_EQUALS("", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: Fred::str1\n", errout.str()); } @@ -2910,7 +2911,8 @@ private: " free(str1);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:17]: (error) Mismatching allocation and deallocation: Fred::str1\n", errout.str()); + ASSERT_EQUALS("", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:17]: (error) Mismatching allocation and deallocation: Fred::str1\n", errout.str()); } void class3() @@ -3057,7 +3059,8 @@ private: " int * p;\n" " A() { p = new int; }\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: A::p\n", errout.str()); + ASSERT_EQUALS("", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: A::p\n", errout.str()); } void class11() @@ -3070,7 +3073,8 @@ private: "};\n" "A::A() : p(new int[10])\n" "{ }"); - ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: A::p\n", errout.str()); + ASSERT_EQUALS("", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: A::p\n", errout.str()); } void class12() @@ -3093,7 +3097,8 @@ private: "\n" "void A::cleanup()\n" "{ delete [] p; }\n"); - ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: A::p\n", errout.str()); + ASSERT_EQUALS("", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: A::p\n", errout.str()); } void class13() @@ -3130,7 +3135,8 @@ private: "\n" "void A::init()\n" "{ p = new int[10]; }\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: A::p\n", errout.str()); + ASSERT_EQUALS("", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: A::p\n", errout.str()); check("class A\n" "{\n" @@ -3141,7 +3147,8 @@ private: "\n" "void A::init()\n" "{ p = new int; }\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: A::p\n", errout.str()); + ASSERT_EQUALS("", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: A::p\n", errout.str()); check("class A\n" "{\n" @@ -3152,7 +3159,8 @@ private: "\n" "void A::init()\n" "{ p = malloc(sizeof(int)*10); }\n"); - ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: A::p\n", errout.str()); + ASSERT_EQUALS("", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: A::p\n", errout.str()); } void class15() @@ -3191,6 +3199,19 @@ private: ASSERT_EQUALS("", errout.str()); } + void class16() + { + // Ticket #1510 + check("class A\n" + "{\n" + " int *a;\n" + " int *b;\n" + "public:\n" + " A() { a = b = new int[10]; }\n" + " ~A() { delete [] a; }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + } void staticvar() { @@ -3291,7 +3312,8 @@ private: "A::~A() {\n" " delete [] pkt_buffer;\n" "}\n"); - ASSERT_EQUALS("[test.cpp:14]: (error) Mismatching allocation and deallocation: A::pkt_buffer\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:14]: (error) Mismatching allocation and deallocation: A::pkt_buffer\n", errout.str()); + ASSERT_EQUALS("", errout.str()); } void func1()