From e664f255a4fef8746258c33aa7f66ff97f995a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 13 Jan 2009 18:30:39 +0000 Subject: [PATCH] Memory leak: Fixed a false positive --- src/checkmemoryleak.cpp | 7 +++++-- test/testmemleak.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 769771f12..d0bef4b04 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -1240,6 +1240,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope(const Token *Tok1, const c void CheckMemoryLeakClass::CheckMemoryLeak_InFunction() { + bool classmember = false; bool infunc = false; int indentlevel = 0; for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) @@ -1250,15 +1251,17 @@ void CheckMemoryLeakClass::CheckMemoryLeak_InFunction() else if (tok->str() == "}") --indentlevel; + if (tok->str() == "::") + classmember = true; // In function.. if (indentlevel == 0) { if (Token::Match(tok, ") {")) - infunc = true; + infunc = !classmember; else if (Token::Match(tok, "[;}]")) - infunc = false; + infunc = classmember = false; } // Declare a local variable => Check diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 6430200ab..029aef5c5 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -134,6 +134,7 @@ private: TEST_CASE(class1); TEST_CASE(class2); // TODO TEST_CASE( class3 ); + TEST_CASE(class4); TEST_CASE(throw1); TEST_CASE(throw2); @@ -1231,6 +1232,29 @@ private: ASSERT_EQUALS(std::string(""), errout.str()); } + void class4() + { + check("struct MONITOR_POST;\n" + "class MonitorClient\n" + "{\n" + "private:\n" + " void addPost(MONITOR_POST *MonitorPost);\n" + "public:\n" + " void click();\n" + "};\n" + "\n" + "void MonitorClient::addPost(MONITOR_POST* MonitorPost)\n" + "{\n" + " _pMonitorPosts->Add(MonitorPost);\n" + "}\n" + "\n" + "void MonitorClient::click()\n" + "{\n" + " MONITOR_POST *NewMeasurePost = new MONITOR_POST;\n" + " addPost( NewMeasurePost );\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + }