CheckMemoryLeak: Removed false positives about not deleting class instances

This commit is contained in:
Daniel Marjamäki 2008-09-29 06:38:25 +00:00
parent 13f5196e52
commit c9fc2594e8
1 changed files with 25 additions and 19 deletions

View File

@ -150,12 +150,12 @@ static void MemoryLeak( const TOKEN *tok, const char varname[] )
ReportErr( errmsg.str() );
}
//---------------------------------------------------------------------------
static void instoken(TOKEN *tok, const char str[])
{
TOKEN *newtok = new TOKEN;
memcpy( newtok, tok, sizeof(TOKEN) );
newtok->str = _strdup(str);
newtok->str = _strdup(str);
tok->next = newtok;
}
//---------------------------------------------------------------------------
@ -163,6 +163,12 @@ static void instoken(TOKEN *tok, const char str[])
extern bool ShowAll;
/**
* Extract a new tokens list that is easier to parse than the "tokens"
* tok - start parse token
* varname - name of variable
*/
static TOKEN *getcode(const TOKEN *tok, const char varname[])
{
const char *varnames[2];
@ -173,7 +179,7 @@ static TOKEN *getcode(const TOKEN *tok, const char varname[])
#define addtoken(_str) \
{ \
TOKEN *newtok = new TOKEN; \
newtok->str = _strdup(_str); \
newtok->str = _strdup(_str); \
newtok->linenr = tok->linenr; \
newtok->FileIndex = tok->FileIndex; \
newtok->next = 0; \
@ -212,14 +218,14 @@ static TOKEN *getcode(const TOKEN *tok, const char varname[])
if ( parlevel == 0 && tok->str[0]==';')
addtoken(";");
if (Match(tok, "[(;{}] %var1% = ", varnames))
if (Match(tok, "[(;{}] %var1% =", varnames))
{
AllocType alloc = GetAllocationType(gettok(tok,3));
// If "--all" hasn't been given, don't check classes..
if ( alloc == New && ! ShowAll )
{
if ( Match(gettok(tok,3), "new %var% ;") )
if ( Match(gettok(tok,3), "new %type% [(;]") )
{
if ( isclass( getstr(tok, 4) ) )
alloc = No;
@ -292,10 +298,10 @@ static TOKEN *getcode(const TOKEN *tok, const char varname[])
addtoken("continue");
if ( Match(tok, "break") )
addtoken("break");
// goto..
if ( Match(tok, "goto") )
addtoken( "goto" );
// goto..
if ( Match(tok, "goto") )
addtoken( "goto" );
// Return..
if ( Match(tok, "return") )
@ -461,7 +467,7 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
erase(tok2, gettok(tok2,3));
done = false;
}
// Replace switch with if (if not complicated)
if (Match(tok2, "switch {"))
{
@ -473,15 +479,15 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
if ( _tok->str[0] == '{' )
break;
else if ( _tok->str[0] == '}' )
else if ( _tok->str[0] == '}' )
{
valid = true;
break;
valid = true;
break;
}
else if (strncmp(_tok->str,"if",2)==0)
break;
else if (strcmp(_tok->str,"switch")==0)
break;
@ -522,17 +528,17 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
instoken( tok2, "else" );
}
while ( tok2 && tok2->str[0] != '}' && ! Match(tok2,"break ;") )
tok2 = tok2->next;
if (Match(tok2,"break ;"))
tok2 = tok2->next;
if (Match(tok2,"break ;"))
{
free(tok2->str);
tok2->str = _strdup(";");
tok2 = tok2->next->next;
tok2 = tok2->next->next;
}
}
}
}
}
}
}