Fixed #1789 (false positive: memory leak (reallocation in subfunction through parameter))

This commit is contained in:
Daniel Marjamäki 2010-07-06 21:36:50 +02:00
parent 1b20f8d27d
commit dc2a0a6468
2 changed files with 22 additions and 16 deletions

View File

@ -526,27 +526,33 @@ const char *CheckMemoryLeak::functionArgAlloc(const Token *tok, unsigned int tar
break;
--indentlevel;
}
if (Token::Match(tok, "free ( * %varid% )", varid))
else if (tok->varId() == varid)
{
realloc = 1;
allocType = No;
}
if (Token::Match(tok, "* %varid% =", varid))
{
allocType = getAllocationType(tok->tokAt(3), varid);
if (allocType == No)
if (Token::Match(tok->tokAt(-3), "free ( * %varid% )", varid))
{
allocType = getReallocationType(tok->tokAt(3), varid);
realloc = 1;
allocType = No;
}
if (allocType != No)
else if (Token::Match(tok->previous(), "* %varid% =", varid))
{
if (realloc)
return "realloc";
return "alloc";
allocType = getAllocationType(tok->tokAt(2), varid);
if (allocType == No)
{
allocType = getReallocationType(tok->tokAt(2), varid);
}
if (allocType != No)
{
if (realloc)
return "realloc";
return "alloc";
}
}
else
{
// unhandled variable usage: bailout
return "";
}
}
if (tok->str() == "return")
return "";
}
return "";

View File

@ -1820,7 +1820,7 @@ private:
" foo(&tmp);\n"
" free(tmp);\n"
"}\n");
TODO_ASSERT_EQUALS(std::string(""), errout.str());
ASSERT_EQUALS(std::string(""), errout.str());
}