From 77c92a0fc8894a8969062d5abeb314989853ed7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 7 Aug 2008 18:53:35 +0000 Subject: [PATCH] Refactoring: Renamed class allocfunc to AllocFunc --- CheckMemoryLeak.cpp | 120 ++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index c8689aaa4..de02c090b 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -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 listallocfunc; + +// Extra allocation.. +class AllocFunc +{ + public: + const char *funcname; + AllocType alloctype; + + AllocFunc(const char f[], AllocType a) + { + funcname = f; + alloctype = a; + } +}; +static std::list 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::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::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