Fix ticket #326 (Reported memory leak when pointer returned by assign to function's parameter)

http://apps.sourceforge.net/trac/cppcheck/ticket/326
This commit is contained in:
Reijo Tomperi 2009-05-22 23:36:03 +03:00
parent 0f20ce738d
commit 0f9b2efa43
2 changed files with 14 additions and 2 deletions

View File

@ -2188,8 +2188,9 @@ bool Tokenizer::simplifyKnownVariables()
break;
}
else if (Token::Match(tok2, "%var% = %num% ;") ||
Token::Match(tok2, "%var% = %bool% ;"))
else if (tok2->previous()->str() != "*" &&
(Token::Match(tok2, "%var% = %num% ;") ||
Token::Match(tok2, "%var% = %bool% ;")))
{
unsigned int varid = tok2->varId();
if (varid == 0)

View File

@ -216,6 +216,7 @@ private:
TEST_CASE(strndup_function);
TEST_CASE(fcloseall_function);
TEST_CASE(pointer_to_pointer);
}
@ -2188,6 +2189,16 @@ private:
ASSERT_EQUALS(std::string(""), errout.str());
}
void pointer_to_pointer()
{
check("void f(char **data)\n"
"{\n"
" char *c = new char[12];\n"
" *c = 0;\n"
" *data = c;\n"
"}\n");
ASSERT_EQUALS(std::string(""), errout.str());
}
};
REGISTER_TEST(TestMemleak)