Fixed #3806 (Possible leak in public function. The pointer '' is not deallocated before it is allocated)

This commit is contained in:
Daniel Marjamäki 2012-05-29 21:13:34 +02:00
parent 8d0f315097
commit 2e41510e30
2 changed files with 13 additions and 1 deletions

View File

@ -2450,7 +2450,7 @@ void CheckMemoryLeakInClass::checkPublicFunctions(const Scope *scope, const Toke
std::list<Function>::const_iterator func;
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
if (func->type != Function::eConstructor &&
if ((func->type == Function::eFunction || func->type == Function::eOperatorEqual) &&
func->access == Public && func->hasBody) {
const Token *tok2 = func->token;
while (tok2->str() != "{")

View File

@ -3840,6 +3840,7 @@ private:
TEST_CASE(class21); // ticket #2517
TEST_CASE(class22); // ticket #3012
TEST_CASE(class23); // ticket #3303
TEST_CASE(class24); // ticket #3806 - false positive in copy constructor
TEST_CASE(staticvar);
@ -4742,6 +4743,17 @@ private:
ASSERT_EQUALS("", errout.str());
}
void class24() { // ticket #3806 - false positive in copy constructor
check("class Fred {\n"
"private:\n"
" int * a;\n"
"public:\n"
" Fred(const Fred &fred) { a = new int; }\n"
" ~Fred() { delete a; }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void staticvar() {
check("class A\n"
"{\n"