CheckMemoryLeak: Handling continue/break

This commit is contained in:
Daniel Marjamäki 2007-05-20 06:35:56 +00:00
parent 685c8560d0
commit 7e54a6af54
1 changed files with 50 additions and 0 deletions

View File

@ -1150,10 +1150,16 @@ void CheckMemoryLeak()
{
std::vector<_variable *> varlist;
// if
int iflevel = 0;
bool endif = false;
std::vector<bool> iflist;
// loop
int looplevel = 0;
bool endloop = false;
std::vector<bool> looplist;
// Parse the statement list and locate memory leaks..
int indentlevel = 0;
std::list<STATEMENT>::const_iterator it;
@ -1166,6 +1172,9 @@ void CheckMemoryLeak()
iflist.push_back(endif);
if (endif)
iflevel++;
looplist.push_back(endloop);
if (endloop)
looplevel++;
break;
case STATEMENT::EBRACE:
@ -1195,6 +1204,11 @@ void CheckMemoryLeak()
iflevel--;
iflist.pop_back();
// loop level..
if (looplist.back())
looplevel--;
looplist.pop_back();
// Make sure the varlist is empty..
if (indentlevel <= 1)
varlist.clear();
@ -1316,9 +1330,45 @@ void CheckMemoryLeak()
}
}
break;
case STATEMENT::CONTINUE:
case STATEMENT::BREAK:
// Memory leak if variable is allocated..
if (looplevel>0)
{
// Find the last loop..
for (int i = looplist.size() - 1; i >= 0; i--)
{
if (!looplist[i])
continue;
int loop_indentlevel = i + 1;
for (i = 0; i < (int)varlist.size(); i++)
{
if (varlist[i]->indentlevel < loop_indentlevel)
continue;
if (varlist[i]->value==_variable::Malloc ||
varlist[i]->value==_variable::New ||
varlist[i]->value==_variable::NewA )
{
std::ostringstream ostr;
ostr << FileLine(it->Token) << ": Memory leak:" << VariableNames[varlist[i]->varindex];
ReportErr(ostr.str());
}
break;
}
break;
}
}
break;
}
endif = (it->Type == STATEMENT::ENDIF);
endloop = (it->Type == STATEMENT::ENDLOOP);
}
}