Refactoring: Renamed class allocfunc to AllocFunc
This commit is contained in:
parent
bbd8c03369
commit
77c92a0fc8
|
@ -15,23 +15,23 @@
|
|||
#endif
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
enum AllocType { No, Malloc, New, NewA };
|
||||
|
||||
// Extra allocation..
|
||||
class allocfunc
|
||||
{
|
||||
public:
|
||||
const char *funcname;
|
||||
AllocType alloctype;
|
||||
|
||||
allocfunc(const char f[], AllocType a)
|
||||
{
|
||||
funcname = f;
|
||||
alloctype = a;
|
||||
}
|
||||
};
|
||||
static std::list<allocfunc> listallocfunc;
|
||||
|
||||
// Extra allocation..
|
||||
class AllocFunc
|
||||
{
|
||||
public:
|
||||
const char *funcname;
|
||||
AllocType alloctype;
|
||||
|
||||
AllocFunc(const char f[], AllocType a)
|
||||
{
|
||||
funcname = f;
|
||||
alloctype = a;
|
||||
}
|
||||
};
|
||||
static std::list<AllocFunc> listallocfunc;
|
||||
|
||||
static AllocType GetAllocationType( const TOKEN *tok2 )
|
||||
{
|
||||
|
@ -67,17 +67,17 @@ static AllocType GetAllocationType( const TOKEN *tok2 )
|
|||
return New;
|
||||
|
||||
if ( Match( tok2, "new %type% [" ) )
|
||||
return NewA;
|
||||
|
||||
// Userdefined allocation function..
|
||||
std::list<allocfunc>::const_iterator it = listallocfunc.begin();
|
||||
while ( it != listallocfunc.end() )
|
||||
{
|
||||
if ( strcmp(tok2->str, it->funcname) == 0 )
|
||||
return it->alloctype;
|
||||
++it;
|
||||
return NewA;
|
||||
|
||||
// Userdefined allocation function..
|
||||
std::list<AllocFunc>::const_iterator it = listallocfunc.begin();
|
||||
while ( it != listallocfunc.end() )
|
||||
{
|
||||
if ( strcmp(tok2->str, it->funcname) == 0 )
|
||||
return it->alloctype;
|
||||
++it;
|
||||
}
|
||||
|
||||
|
||||
return No;
|
||||
}
|
||||
|
||||
|
@ -239,7 +239,7 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
return;
|
||||
|
||||
// Linux lists.. todo: check if the first struct member is passed
|
||||
if ( Match( tok, "%var% ( & %var1% .", varnames ) ||
|
||||
if ( Match( tok, "%var% ( & %var1% .", varnames ) ||
|
||||
Match( tok, ", & %var1% .", varnames ) )
|
||||
{
|
||||
return;
|
||||
|
@ -273,37 +273,37 @@ static void CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const char varname[]
|
|||
}
|
||||
|
||||
if ( ! retvar )
|
||||
MemoryLeak( tok, varname );
|
||||
|
||||
else
|
||||
{
|
||||
// The allocated memory is returned.. check that it is deallocated
|
||||
|
||||
// Get function name..
|
||||
const char *funcname = 0;
|
||||
int indentlevel = 0;
|
||||
for ( const TOKEN *ftok = tokens; ftok && ftok != tok; ftok = ftok->next )
|
||||
{
|
||||
if ( ftok->str[0] == '{' )
|
||||
indentlevel++;
|
||||
|
||||
else if ( ftok->str[0] == '}' )
|
||||
indentlevel--;
|
||||
|
||||
if ( indentlevel <= 0 )
|
||||
{
|
||||
if ( Match(ftok, "[};]") )
|
||||
funcname = 0;
|
||||
else if ( Match(ftok, "%var% (") )
|
||||
funcname = ftok->str;
|
||||
}
|
||||
}
|
||||
|
||||
if ( funcname )
|
||||
{
|
||||
listallocfunc.push_back( allocfunc(funcname, Alloc) );
|
||||
}
|
||||
}
|
||||
MemoryLeak( tok, varname );
|
||||
|
||||
else
|
||||
{
|
||||
// The allocated memory is returned.. check that it is deallocated
|
||||
|
||||
// Get function name..
|
||||
const char *funcname = 0;
|
||||
int indentlevel = 0;
|
||||
for ( const TOKEN *ftok = tokens; ftok && ftok != tok; ftok = ftok->next )
|
||||
{
|
||||
if ( ftok->str[0] == '{' )
|
||||
indentlevel++;
|
||||
|
||||
else if ( ftok->str[0] == '}' )
|
||||
indentlevel--;
|
||||
|
||||
if ( indentlevel <= 0 )
|
||||
{
|
||||
if ( Match(ftok, "[};]") )
|
||||
funcname = 0;
|
||||
else if ( Match(ftok, "%var% (") )
|
||||
funcname = ftok->str;
|
||||
}
|
||||
}
|
||||
|
||||
if ( funcname )
|
||||
{
|
||||
listallocfunc.push_back( AllocFunc(funcname, Alloc) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( indentlevel <= alloc_indentlevel )
|
||||
return;
|
||||
|
@ -529,8 +529,8 @@ static void CheckMemoryLeak_ClassMembers_Variable( const std::vector<const char
|
|||
//---------------------------------------------------------------------------
|
||||
|
||||
void CheckMemoryLeak()
|
||||
{
|
||||
listallocfunc.clear();
|
||||
{
|
||||
listallocfunc.clear();
|
||||
|
||||
// Check for memory leaks inside functions..
|
||||
CheckMemoryLeak_InFunction();
|
||||
|
|
Loading…
Reference in New Issue