Fixed #555 (False positive: [CuTest.c:25]: (error) Memory leak: len)

This commit is contained in:
Daniel Marjamäki 2009-08-05 21:18:16 +02:00
parent e1beb70f80
commit ce8c5b0236
2 changed files with 18 additions and 1 deletions

View File

@ -942,7 +942,8 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
const char *str = call_func(tok, callstack, varnames, alloctype, dealloctype, all, sz); const char *str = call_func(tok, callstack, varnames, alloctype, dealloctype, all, sz);
if (str) if (str)
{ {
addtoken(str); if (Token::simpleMatch(tok->tokAt(-2), (varnameStr + " =").c_str()) || std::string(str) != "alloc")
addtoken(str);
} }
else else
{ {

View File

@ -209,6 +209,7 @@ private:
TEST_CASE(func15); TEST_CASE(func15);
TEST_CASE(allocfunc1); TEST_CASE(allocfunc1);
TEST_CASE(allocfunc2);
TEST_CASE(throw1); TEST_CASE(throw1);
TEST_CASE(throw2); TEST_CASE(throw2);
@ -1530,6 +1531,21 @@ private:
ASSERT_EQUALS(std::string("[test.cpp:8]: (error) Memory leak: p\n"), errout.str()); ASSERT_EQUALS(std::string("[test.cpp:8]: (error) Memory leak: p\n"), errout.str());
} }
void allocfunc2()
{
check("static char *a(int size)\n"
"{\n"
" return new char[size];\n"
"}\n"
"static void b()\n"
"{\n"
" int len = 100;\n"
" char *p = a(len);\n"
" delete [] p;\n"
"}\n");
ASSERT_EQUALS(std::string(""), errout.str());
}