diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 46862745a..d2dde8d32 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -5198,6 +5198,8 @@ private: void run() { // pass allocated memory to function.. TEST_CASE(functionParameter); + // never use leakable resource + TEST_CASE(missingAssignement); } void functionParameter() { @@ -5235,5 +5237,23 @@ private: "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Allocation with strdup, mkstemp doesn't release it.\n", "", errout.str()); } + + void missingAssignement() { + check("void x()\n" + "{\n" + " malloc(10);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:2]: (error) Allocation with malloc never assigned.\n", errout.str()); + + check("void *f()\n" + "{\n" + " return malloc(10);\n" + "}\n" + "void x()\n" + "{\n" + " f();\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:6]: (error) Allocation with f never assigned.\n", errout.str()); + } }; static TestMemleakNoVar testMemleakNoVar;