Fixed #2921 (False positive: Memory leak with static pointer)

This commit is contained in:
Daniel Marjamäki 2011-07-24 16:08:29 +02:00
parent 4d76085757
commit 4e6800c474
2 changed files with 18 additions and 0 deletions

View File

@ -467,6 +467,10 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Token *tok,
{
return No;
}
if (Token::Match(tok, "static %type% * %varid% [;{}=]", varid))
{
return No;
}
if (Token::Match(tok, "[(,] %varid% [,)]", varid))
{
return No;

View File

@ -244,6 +244,7 @@ private:
TEST_CASE(allocfunc7);
TEST_CASE(allocfunc8);
TEST_CASE(allocfunc9);
TEST_CASE(allocfunc10);
TEST_CASE(throw1);
TEST_CASE(throw2);
@ -2528,6 +2529,19 @@ private:
ASSERT_EQUALS("", errout.str());
}
void allocfunc10()
{
// Ticket #2921 - static pointer
check("char *getstr() {\n"
" static char *ret = malloc(100);\n"
" return ret;\n"
"}\n"
"\n"
"void foo() {\n"
" char *s = getstr();\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void throw1()
{