Fixed #4367 (false positive: Class '...' is unsafe, '...' can leak by wrong usage)

This commit is contained in:
Daniel Marjamäki 2013-02-24 08:14:25 +01:00
parent 5c7e1cf9ff
commit 2edf95a1b9
2 changed files with 19 additions and 2 deletions

View File

@ -2380,10 +2380,15 @@ void CheckMemoryLeakInClass::variable(const Scope *scope, const Token *tokVarnam
// Inspect member functions
std::list<Function>::const_iterator func;
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
if (!func->hasBody)
continue;
const bool constructor = func->type == Function::eConstructor;
const bool destructor = func->type == Function::eDestructor;
if (!func->hasBody) {
if (destructor) { // implementation for destructor is not seen => assume it deallocates all variables properly
deallocInDestructor = true;
Dealloc = CheckMemoryLeak::Many;
}
continue;
}
bool body = false;
const Token *end = func->functionScope->classEnd;
for (const Token *tok = func->arg->link(); tok != end; tok = tok->next()) {

View File

@ -3935,6 +3935,7 @@ private:
TEST_CASE(class22); // ticket #3012
TEST_CASE(class23); // ticket #3303
TEST_CASE(class24); // ticket #3806 - false positive in copy constructor
TEST_CASE(class25); // ticket #4367 - false positive implementation for destructor is not seen
TEST_CASE(staticvar);
@ -4848,6 +4849,17 @@ private:
ASSERT_EQUALS("", errout.str());
}
void class25() { // ticket #4367 - false positive when implementation for destructor is not seen
check("class Fred {\n"
"private:\n"
" int * a;\n"
"public:\n"
" Fred() { a = new int; }\n"
" ~Fred();\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void staticvar() {
check("class A\n"
"{\n"