Fixed #555 (False positive: [CuTest.c:25]: (error) Memory leak: len)
This commit is contained in:
parent
e1beb70f80
commit
ce8c5b0236
|
@ -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);
|
||||
if (str)
|
||||
{
|
||||
addtoken(str);
|
||||
if (Token::simpleMatch(tok->tokAt(-2), (varnameStr + " =").c_str()) || std::string(str) != "alloc")
|
||||
addtoken(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -209,6 +209,7 @@ private:
|
|||
TEST_CASE(func15);
|
||||
|
||||
TEST_CASE(allocfunc1);
|
||||
TEST_CASE(allocfunc2);
|
||||
|
||||
TEST_CASE(throw1);
|
||||
TEST_CASE(throw2);
|
||||
|
@ -1530,6 +1531,21 @@ private:
|
|||
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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue