diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 7fc53f483..8522f6420 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -2058,6 +2058,12 @@ void CheckMemoryLeakInClass::parseClass(const Token *tok1, std::vector 0) continue; + // skip static variables.. + if (Token::Match(tok, "static %type% * %var% ;")) + { + tok = tok->tokAt(4); + } + // Declaring subclass.. recursive checking if (Token::Match(tok, "class %var% [{:]")) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 38db4edea..86af54184 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2410,6 +2410,8 @@ private: TEST_CASE(class10); TEST_CASE(class11); + TEST_CASE(staticvar); + TEST_CASE(use); TEST_CASE(free_member_in_sub_func); @@ -2628,6 +2630,23 @@ private: } + void staticvar() + { + check("class A\n" + "{\n" + "private:\n" + " static int * p;\n" + "public:" + " A()\n" + " {\n" + " if (!p)\n" + " p = new int[100];\n" + " }\n" + "};\n", true); + ASSERT_EQUALS("", errout.str()); + } + + void use() { check("class A\n"