Refactoring: Renamed class allocfunc to AllocFunc

This commit is contained in:
Daniel Marjamäki 2008-08-07 18:53:35 +00:00
parent bbd8c03369
commit 77c92a0fc8
1 changed files with 60 additions and 60 deletions

View File

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