Valgrind: Fixed memory leaks when running testrunner that was found by Valgrind

This commit is contained in:
Daniel Marjamäki 2009-12-28 19:48:30 +01:00
parent 61e61c1584
commit d3d3ad101f
2 changed files with 42 additions and 13 deletions

View File

@ -56,6 +56,16 @@ bool ExecutionPath::parseCondition(const Token &tok, std::list<ExecutionPath *>
}
static void dealloc_checks(std::list<ExecutionPath *> &checks)
{
while (!checks.empty())
{
delete checks.back();
checks.pop_back();
}
}
static const Token *checkExecutionPaths_(const Token *tok, std::list<ExecutionPath *> &checks)
{
const std::auto_ptr<ExecutionPath> check(checks.front()->copy());
@ -100,12 +110,8 @@ static const Token *checkExecutionPaths_(const Token *tok, std::list<ExecutionPa
// parse condition
if (checks.size() > 10 || check->parseCondition(*tok->next(), checks))
{
while (!checks.empty())
{
delete checks.back();
checks.pop_back();
}
dealloc_checks(checks);
dealloc_checks(newchecks);
return 0;
}
@ -116,7 +122,11 @@ static const Token *checkExecutionPaths_(const Token *tok, std::list<ExecutionPa
tok = tok ? tok->next() : 0;
if (!Token::simpleMatch(tok, "{"))
{
dealloc_checks(checks);
dealloc_checks(newchecks);
return 0;
}
// Recursively check into the if ..
{
@ -126,7 +136,11 @@ static const Token *checkExecutionPaths_(const Token *tok, std::list<ExecutionPa
c.push_back((*it)->copy());
const Token *tokerr = checkExecutionPaths_(tok->next(), c);
if (tokerr)
{
dealloc_checks(c);
dealloc_checks(newchecks);
return tokerr;
}
while (!c.empty())
{
newchecks.push_back(c.back());
@ -149,16 +163,22 @@ static const Token *checkExecutionPaths_(const Token *tok, std::list<ExecutionPa
// there is no "if"..
const Token *tokerr = checkExecutionPaths_(tok->next(), checks);
if (tokerr)
{
dealloc_checks(newchecks);
return tokerr;
}
tok = tok->link();
if (!tok)
{
dealloc_checks(newchecks);
return 0;
}
}
std::list<ExecutionPath *>::iterator it;
for (it = newchecks.begin(); it != newchecks.end(); ++it)
checks.push_back((*it)->copy());
checks.push_back(*it);
}
@ -193,7 +213,6 @@ static const Token *checkExecutionPaths_(const Token *tok, std::list<ExecutionPa
return 0;
}
void checkExecutionPaths(const Token *tok, ExecutionPath *c)
{
for (; tok; tok = tok->next())

View File

@ -1693,7 +1693,13 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file
if (macro->name().empty())
delete macro;
else
{
std::map<std::string, PreprocessorMacro *>::iterator it;
it = macros.find(macro->name());
if (it != macros.end())
delete it->second;
macros[macro->name()] = macro;
}
line = "\n";
}
@ -1759,6 +1765,11 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file
errorLogger,
"noQuoteCharPair",
std::string("No pair for character (") + ch + "). Can't process file. File is either invalid or unicode, which is currently not supported.");
std::map<std::string, PreprocessorMacro *>::iterator it;
for (it = macros.begin(); it != macros.end(); ++it)
delete it->second;
return "";
}
@ -1882,11 +1893,10 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file
errorLogger,
"syntaxError",
std::string("Syntax error. Not enough parameters for macro '") + macro->name() + "'.");
{
std::map<std::string, PreprocessorMacro *>::iterator it;
for (it = macros.begin(); it != macros.end(); ++it)
delete it->second;
}
std::map<std::string, PreprocessorMacro *>::iterator it;
for (it = macros.begin(); it != macros.end(); ++it)
delete it->second;
return "";
}