Fixed #253 (MemoryLeakInClass: False positive when memory is released in function, which is called from destructor)

This commit is contained in:
Daniel Marjamäki 2009-10-24 15:07:14 +02:00
parent 39c9a2a4da
commit 26a81e82cc
2 changed files with 14 additions and 7 deletions

View File

@ -2155,10 +2155,6 @@ void CheckMemoryLeakInClass::variable(const char classname[], const Token *tokVa
if (indent == 0) if (indent == 0)
continue; continue;
// Function call in destructor.. possible deallocation
if (destructor && Token::Match(tok, "[{};] %var% ("))
deallocInDestructor = true;
// Deallocate.. // Deallocate..
const char *varnames[3] = { "var", 0, 0 }; const char *varnames[3] = { "var", 0, 0 };
varnames[0] = varname; varnames[0] = varname;
@ -2187,6 +2183,17 @@ void CheckMemoryLeakInClass::variable(const char classname[], const Token *tokVa
Dealloc = dealloc; Dealloc = dealloc;
} }
// Function call in destructor .. possible deallocation
else if (destructor && Token::Match(tok->previous(), "[{};] %var% ("))
{
if (!std::bsearch(tok->strAt(0), call_func_white_list,
sizeof(call_func_white_list) / sizeof(call_func_white_list[0]),
sizeof(call_func_white_list[0]), call_func_white_list_compare))
{
return;
}
}
} }
} }

View File

@ -2564,7 +2564,7 @@ private:
" }\n" " }\n"
"}\n", true); "}\n", true);
TODO_ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void class4() void class4()
@ -2799,7 +2799,7 @@ private:
"{\n" "{\n"
" delete tok;\n" " delete tok;\n"
"}\n", true); "}\n", true);
TODO_ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// Global function // Global function
check("void deleteTokens(int *tok)\n" check("void deleteTokens(int *tok)\n"
@ -2826,7 +2826,7 @@ private:
" deleteTokens(_tokens);\n" " deleteTokens(_tokens);\n"
" _tokens = 0;\n" " _tokens = 0;\n"
"}\n", true); "}\n", true);
TODO_ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
}; };