Fixed #1146 (improve check: memory leak not detected (allocation in subfunction))

This commit is contained in:
Daniel Marjamäki 2010-04-24 20:40:57 +02:00
parent 5b99f2cef1
commit 5e5b8d3861
2 changed files with 20 additions and 0 deletions

View File

@ -423,6 +423,12 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Token *tok)
continue;
}
if (tok->str() == ";")
{
tok = tok->next();
continue;
}
if (tok->str() == "return")
{
if (varid > 0 && Token::Match(tok->next(), "%varid% ;", varid))

View File

@ -295,6 +295,7 @@ private:
TEST_CASE(allocfunc1);
TEST_CASE(allocfunc2);
TEST_CASE(allocfunc3);
TEST_CASE(throw1);
TEST_CASE(throw2);
@ -1666,6 +1667,19 @@ private:
ASSERT_EQUALS(std::string(""), errout.str());
}
void allocfunc3()
{
check("static char *a()\n"
"{\n"
" char *data = malloc(10);;"
" return data;\n"
"}\n"
"static void b()\n"
"{\n"
" char *p = a();\n"
"}\n");
ASSERT_EQUALS(std::string("[test.cpp:8]: (error) Memory leak: p\n"), errout.str());
}