Fixed #1789 (false positive: memory leak (reallocation in subfunction through parameter))
This commit is contained in:
parent
1b20f8d27d
commit
dc2a0a6468
|
@ -526,17 +526,19 @@ const char *CheckMemoryLeak::functionArgAlloc(const Token *tok, unsigned int tar
|
||||||
break;
|
break;
|
||||||
--indentlevel;
|
--indentlevel;
|
||||||
}
|
}
|
||||||
if (Token::Match(tok, "free ( * %varid% )", varid))
|
else if (tok->varId() == varid)
|
||||||
|
{
|
||||||
|
if (Token::Match(tok->tokAt(-3), "free ( * %varid% )", varid))
|
||||||
{
|
{
|
||||||
realloc = 1;
|
realloc = 1;
|
||||||
allocType = No;
|
allocType = No;
|
||||||
}
|
}
|
||||||
if (Token::Match(tok, "* %varid% =", varid))
|
else if (Token::Match(tok->previous(), "* %varid% =", varid))
|
||||||
{
|
{
|
||||||
allocType = getAllocationType(tok->tokAt(3), varid);
|
allocType = getAllocationType(tok->tokAt(2), varid);
|
||||||
if (allocType == No)
|
if (allocType == No)
|
||||||
{
|
{
|
||||||
allocType = getReallocationType(tok->tokAt(3), varid);
|
allocType = getReallocationType(tok->tokAt(2), varid);
|
||||||
}
|
}
|
||||||
if (allocType != No)
|
if (allocType != No)
|
||||||
{
|
{
|
||||||
|
@ -545,9 +547,13 @@ const char *CheckMemoryLeak::functionArgAlloc(const Token *tok, unsigned int tar
|
||||||
return "alloc";
|
return "alloc";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tok->str() == "return")
|
else
|
||||||
|
{
|
||||||
|
// unhandled variable usage: bailout
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1820,7 +1820,7 @@ private:
|
||||||
" foo(&tmp);\n"
|
" foo(&tmp);\n"
|
||||||
" free(tmp);\n"
|
" free(tmp);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
TODO_ASSERT_EQUALS(std::string(""), errout.str());
|
ASSERT_EQUALS(std::string(""), errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue