Memory leaks: less conservative checking of classes. ticket: #2517

This commit is contained in:
Robert Reif 2011-01-30 08:38:20 +01:00 committed by Daniel Marjamäki
parent 49fc53165c
commit 09998d9e18
2 changed files with 42 additions and 2 deletions

View File

@ -2727,8 +2727,8 @@ void CheckMemoryLeakInClass::check()
// known class?
else if (var->type())
{
// not derived and no constructor?
if (var->type()->derivedFrom.empty() && var->type()->numConstructors == 0)
// not derived?
if (var->type()->derivedFrom.empty())
{
if (var->isPrivate())
checkPublicFunctions(scope, var->nameToken());

View File

@ -3165,6 +3165,7 @@ private:
TEST_CASE(class18);
TEST_CASE(class19); // ticket #2219
TEST_CASE(class20);
TEST_CASE(class21); // ticket #2517
TEST_CASE(staticvar);
@ -4018,6 +4019,45 @@ private:
ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: Fred::str1\n", errout.str());
}
void class21() // ticket #2517
{
check("struct B { };\n"
"struct C\n"
"{\n"
" B * b;\n"
" C(B * x) : b(x) { }\n"
"};\n"
"class A\n"
"{\n"
" B *b;\n"
" C *c;\n"
"public:\n"
" A() : b(new B()), c(new C(b)) { }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:9]: (error) Memory leak: A::b\n"
"[test.cpp:10]: (error) Memory leak: A::c\n", errout.str());
check("struct B { };\n"
"struct C\n"
"{\n"
" B * b;\n"
" C(B * x) : b(x) { }\n"
"};\n"
"class A\n"
"{\n"
" B *b;\n"
" C *c;\n"
"public:\n"
" A()\n"
" {\n"
" b = new B();\n"
" c = new C(b);\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:9]: (error) Memory leak: A::b\n"
"[test.cpp:10]: (error) Memory leak: A::c\n", errout.str());
}
void staticvar()
{
check("class A\n"