diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 46c176201..44ec9e204 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -3132,6 +3132,28 @@ private: "void A::init()\n" "{ p = new int[10]; }\n"); ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: A::p\n", errout.str()); + + check("class A\n" + "{\n" + " int *p;\n" + "public:\n" + " void init();\n" + "};\n" + "\n" + "void A::init()\n" + "{ p = new int; }\n"); + ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: A::p\n", errout.str()); + + check("class A\n" + "{\n" + " int *p;\n" + "public:\n" + " void init();\n" + "};\n" + "\n" + "void A::init()\n" + "{ p = malloc(sizeof(int)*10); }\n"); + ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: A::p\n", errout.str()); } void class15() @@ -3146,6 +3168,28 @@ private: "A::A()\n" "{ p = new int[10]; }"); ASSERT_EQUALS("", errout.str()); + + check("class A\n" + "{\n" + " int *p;\n" + "public:\n" + " A();\n" + " ~A() { delete p; }\n" + "};\n" + "A::A()\n" + "{ p = new int; }"); + ASSERT_EQUALS("", errout.str()); + + check("class A\n" + "{\n" + " int *p;\n" + "public:\n" + " A();\n" + " ~A() { free(p); }\n" + "};\n" + "A::A()\n" + "{ p = malloc(sizeof(int)*10); }"); + ASSERT_EQUALS("", errout.str()); } void class16() // ticket 1788