From 44a5cecd992ffcbb7c56c541b41d217c8f2af3b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 23 Feb 2009 19:32:54 +0000 Subject: [PATCH] memory leaks: improved handling of --vcl --- src/checkmemoryleak.cpp | 4 ++++ test/testmemleak.cpp | 35 ++++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 3f6baf652..7b1d27721 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -1441,6 +1441,10 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_ParseClass(const Token * // Declaring member variable.. check allocations and deallocations if (Token::Match(tok->next(), "%type% * %var% ;")) { + // No false positives for vcl classes.. + if (_settings._vcl && tok->next()->str()[0] == 'T') + continue; + if (tok->isName() || Token::Match(tok, "[;}]")) { if (_settings._showAll || !isclass(tok->tokAt(1))) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 504d3ca14..033ee3be4 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -195,6 +195,7 @@ private: // VCL.. TEST_CASE(vcl1); + TEST_CASE(vcl2); } @@ -1891,14 +1892,8 @@ private: - - void vcl1() + void checkvcl(const char code[]) { - const char code[] = "void Form1::foo()\n" - "{\n" - " TEdit *Edit1 = new TEdit(this);\n" - "}\n"; - // Tokenize.. Tokenizer tokenizer; std::istringstream istr(code); @@ -1916,10 +1911,36 @@ private: settings._vcl = true; CheckMemoryLeakClass checkMemoryLeak(&tokenizer, settings, this); checkMemoryLeak.CheckMemoryLeak(); + } + + + void vcl1() + { + checkvcl("void Form1::foo()\n" + "{\n" + " TEdit *Edit1 = new TEdit(this);\n" + "}\n"); ASSERT_EQUALS("", errout.str()); } + + void vcl2() + { + checkvcl("class Fred\n" + "{\n" + "private:\n" + " TButton *button;\n" + "public:\n" + " Fred();\n" + "};\n" + "\n" + "Fred::Fred()\n" + "{\n" + " button = new TButton(this);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestMemleak)