Fix ticket #196 (False positive: Resource leak)
http://apps.sourceforge.net/trac/cppcheck/ticket/196
This commit is contained in:
parent
e37da13c26
commit
a46de47158
|
@ -331,10 +331,7 @@ bool CheckMemoryLeakClass::notvar(const Token *tok, const char *varnames[], bool
|
|||
const std::string end(endpar ? " &&|)" : " [;)&|]");
|
||||
|
||||
return bool(Token::Match(tok, ("! " + varname + end).c_str()) ||
|
||||
Token::Match(tok, ("! ( " + varname + " )" + end).c_str()) ||
|
||||
Token::Match(tok, ("0 == " + varname + end).c_str()) ||
|
||||
Token::Match(tok, (varname + " == 0" + end).c_str()) ||
|
||||
Token::Match(tok, ("( " + varname + " ) == 0" + end).c_str()));
|
||||
Token::Match(tok, ("! ( " + varname + " )" + end).c_str()));
|
||||
}
|
||||
|
||||
Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *> callstack, const char varname[], AllocType &alloctype, AllocType &dealloctype, bool classmember, bool &all, unsigned int sz)
|
||||
|
@ -557,9 +554,23 @@ Token *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *>
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (Token::simpleMatch(tok, std::string("if ( ! " + varnameStr + " &&").c_str()))
|
||||
{
|
||||
addtoken("if(!var)");
|
||||
}
|
||||
else if (tok->next() &&
|
||||
tok->next()->link() &&
|
||||
Token::simpleMatch(tok->next()->link()->previous()->previous()->previous(), std::string("&& ! " + varnameStr).c_str()))
|
||||
{
|
||||
addtoken("if(!var)");
|
||||
}
|
||||
else
|
||||
{
|
||||
addtoken((dep ? "ifv" : "if"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((tok->str() == "else") || (tok->str() == "switch"))
|
||||
{
|
||||
|
|
|
@ -2108,7 +2108,7 @@ private:
|
|||
"\n"
|
||||
" delete [] a;\n"
|
||||
"}\n", true);
|
||||
TODO_ASSERT_EQUALS("", errout.str());
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue