diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 9832c5ec6..d525ca81d 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -942,7 +942,8 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::listtokAt(-2), (varnameStr + " =").c_str()) || std::string(str) != "alloc") + addtoken(str); } else { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 818154277..c2b195fc8 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -209,6 +209,7 @@ private: TEST_CASE(func15); TEST_CASE(allocfunc1); + TEST_CASE(allocfunc2); TEST_CASE(throw1); TEST_CASE(throw2); @@ -1530,6 +1531,21 @@ private: ASSERT_EQUALS(std::string("[test.cpp:8]: (error) Memory leak: p\n"), errout.str()); } + void allocfunc2() + { + check("static char *a(int size)\n" + "{\n" + " return new char[size];\n" + "}\n" + "static void b()\n" + "{\n" + " int len = 100;\n" + " char *p = a(len);\n" + " delete [] p;\n" + "}\n"); + ASSERT_EQUALS(std::string(""), errout.str()); + } +