Fixed #2673 (false positive: memory leak (address stored in list))
This commit is contained in:
parent
61e720c82b
commit
74105f5d83
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue