Memory leaks: Determine that some classes are not auto-deallocated. Reduce false negatives. Ticket: #2219 and #1618
This commit is contained in:
parent
ca8f5015b8
commit
758fc85a12
|
@ -2616,9 +2616,18 @@ void CheckMemoryLeakInClass::check()
|
|||
|
||||
variable(info, var->token);
|
||||
}
|
||||
else
|
||||
|
||||
// known class?
|
||||
else if (var->type)
|
||||
{
|
||||
/** @todo false negative: check classes here someday */
|
||||
// not derived and no constructor?
|
||||
if (var->type->derivedFrom.empty() && var->type->numConstructors == 0)
|
||||
{
|
||||
if (var->access == SymbolDatabase::Private)
|
||||
checkPublicFunctions(info, var->token);
|
||||
|
||||
variable(info, var->token);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1087,21 +1087,25 @@ void SymbolDatabase::SpaceInfo::getVarList()
|
|||
else if (Token::Match(tok, "%type% * %var% ;"))
|
||||
{
|
||||
vartok = tok->tokAt(2);
|
||||
typetok = tok;
|
||||
tok = vartok->next();
|
||||
}
|
||||
else if (Token::Match(tok, "%type% %type% * %var% ;"))
|
||||
{
|
||||
vartok = tok->tokAt(3);
|
||||
typetok = vartok->tokAt(-2);
|
||||
tok = vartok->next();
|
||||
}
|
||||
else if (Token::Match(tok, "%type% :: %type% * %var% ;"))
|
||||
{
|
||||
vartok = tok->tokAt(4);
|
||||
typetok = vartok->tokAt(-2);
|
||||
tok = vartok->next();
|
||||
}
|
||||
else if (Token::Match(tok, "%type% :: %type% :: %type% * %var% ;"))
|
||||
{
|
||||
vartok = tok->tokAt(6);
|
||||
typetok = vartok->tokAt(-2);
|
||||
tok = vartok->next();
|
||||
}
|
||||
|
||||
|
@ -1221,7 +1225,7 @@ void SymbolDatabase::SpaceInfo::getVarList()
|
|||
|
||||
const SpaceInfo *spaceInfo = NULL;
|
||||
|
||||
if (isClass)
|
||||
if (typetok)
|
||||
spaceInfo = check->findVarType(this, typetok);
|
||||
|
||||
addVar(vartok, varaccess, isMutable, isStatic, isConst, isClass, spaceInfo);
|
||||
|
|
|
@ -3579,6 +3579,45 @@ private:
|
|||
" rp2 = new TRadioButton(this);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("class TRadioButton { };\n"
|
||||
"class Foo\n"
|
||||
"{\n"
|
||||
"private:\n"
|
||||
" TRadioButton* rp1;\n"
|
||||
" TRadioButton* rp2;\n"
|
||||
"public:\n"
|
||||
" Foo();\n"
|
||||
"};\n"
|
||||
"Foo::Foo()\n"
|
||||
"{\n"
|
||||
" rp1 = new TRadioButton;\n"
|
||||
" rp2 = new TRadioButton;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: Foo::rp1\n"
|
||||
"[test.cpp:6]: (error) Memory leak: Foo::rp2\n", errout.str());
|
||||
|
||||
check("class TRadioButton { };\n"
|
||||
"class Foo\n"
|
||||
"{\n"
|
||||
"private:\n"
|
||||
" TRadioButton* rp1;\n"
|
||||
" TRadioButton* rp2;\n"
|
||||
"public:\n"
|
||||
" Foo();\n"
|
||||
" ~Foo();\n"
|
||||
"};\n"
|
||||
"Foo::Foo()\n"
|
||||
"{\n"
|
||||
" rp1 = new TRadioButton;\n"
|
||||
" rp2 = new TRadioButton;\n"
|
||||
"}\n"
|
||||
"Foo::~Foo()\n"
|
||||
"{\n"
|
||||
" delete rp1;\n"
|
||||
" delete rp2;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void staticvar()
|
||||
|
|
Loading…
Reference in New Issue