memory leaks: improved handling of --vcl

This commit is contained in:
Daniel Marjamäki 2009-02-23 19:32:54 +00:00
parent a7b0c30884
commit 44a5cecd99
2 changed files with 32 additions and 7 deletions

View File

@ -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)))

View File

@ -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)