Fixed #2673 (false positive: memory leak (address stored in list))

This commit is contained in:
Daniel Marjamäki 2011-03-24 17:14:12 +01:00
parent 61e720c82b
commit 74105f5d83
2 changed files with 20 additions and 0 deletions

View File

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

View File

@ -240,6 +240,7 @@ private:
TEST_CASE(allocfunc6);
TEST_CASE(allocfunc7);
TEST_CASE(allocfunc8);
TEST_CASE(allocfunc9);
TEST_CASE(throw1);
TEST_CASE(throw2);
@ -2440,6 +2441,21 @@ private:
ASSERT_EQUALS("[test.cpp:7]: (error) Resource leak: f\n", errout.str());
}
void allocfunc9()
{
// Ticket #2673 - address is taken in alloc func
check("char *addstring(const char *s) {\n"
" char *ret = strdup(s);\n"
" strings.push_back(ret);"
" return ret;\n"
"}\n"
"\n"
"void foo() {\n"
" char *s = addstring(\"abc\");\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void throw1()
{