Fix ticket #196 (False positive: Resource leak)

http://apps.sourceforge.net/trac/cppcheck/ticket/196
This commit is contained in:
Reijo Tomperi 2009-05-01 14:39:57 +03:00
parent e37da13c26
commit a46de47158
2 changed files with 18 additions and 7 deletions

View File

@ -331,10 +331,7 @@ bool CheckMemoryLeakClass::notvar(const Token *tok, const char *varnames[], bool
const std::string end(endpar ? " &&|)" : " [;)&|]"); const std::string end(endpar ? " &&|)" : " [;)&|]");
return bool(Token::Match(tok, ("! " + varname + end).c_str()) || return bool(Token::Match(tok, ("! " + varname + end).c_str()) ||
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 *CheckMemoryLeakClass::getcode(const Token *tok, std::list<const Token *> callstack, const char varname[], AllocType &alloctype, AllocType &dealloctype, bool classmember, bool &all, unsigned int sz) 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; 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")); addtoken((dep ? "ifv" : "if"));
} }
} }
}
if ((tok->str() == "else") || (tok->str() == "switch")) if ((tok->str() == "else") || (tok->str() == "switch"))
{ {

View File

@ -2108,7 +2108,7 @@ private:
"\n" "\n"
" delete [] a;\n" " delete [] a;\n"
"}\n", true); "}\n", true);
TODO_ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
}; };