Fixed #727 (False positive: Resource leak when release is done inside function call)

This commit is contained in:
Daniel Marjamäki 2009-10-04 13:10:08 +02:00
parent 3c5b13a276
commit af5a695f82
2 changed files with 9 additions and 1 deletions

View File

@ -534,7 +534,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
--parlevel;
if (parlevel < 1)
{
return _settings->_showAll ? 0 : "callfunc";
return (_settings && _settings->_showAll) ? 0 : "callfunc";
}
}
@ -1073,6 +1073,13 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
else
{
if (varid > 0 && Token::Match(tok, "%var% ( fclose|pclose ( %varid% ) ) ;", varid))
{
addtoken("dealloc");
tok = tok->next()->link();
continue;
}
const char *str = call_func(tok, callstack, varid, alloctype, dealloctype, all, sz);
if (str)
{

View File

@ -339,6 +339,7 @@ private:
TODO_ASSERT_EQUALS(";;dealloc;", getcode("char *s; delete (void *)(s);", "s"));
ASSERT_EQUALS(";;dealloc;", getcode("char *s; delete [] s;", "s"));
ASSERT_EQUALS(";;dealloc;", getcode("char *s; delete [] (s);", "s"));
ASSERT_EQUALS(";;dealloc;", getcode("void *p; foo(fclose(p));", "p"));
// if..
ASSERT_EQUALS(";;if{}", getcode("char *s; if (a) { }", "s"));