Cppcheck
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Static Private Member Functions | List of all members
CheckMemoryLeakInClass Class Reference

Check class variables, variables that are allocated in the constructor should be deallocated in the destructor More...

#include <checkmemoryleak.h>

Inheritance diagram for CheckMemoryLeakInClass:
Check CheckMemoryLeak

Public Member Functions

 CheckMemoryLeakInClass ()
 
 CheckMemoryLeakInClass (const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog)
 
void runSimplifiedChecks (const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog)
 run checks, the token list is simplified More...
 
void check ()
 

Private Member Functions

void variable (const Scope *scope, const Token *tokVarname)
 
void checkPublicFunctions (const Scope *scope, const Token *classtok)
 Public functions: possible double-allocation. More...
 
void publicAllocationError (const Token *tok, const std::string &varname)
 
void unsafeClassError (const Token *tok, const std::string &classname, const std::string &varname)
 
void getErrorMessages (ErrorLogger *e, const Settings *settings) const
 get error messages More...
 
std::string classInfo () const
 get information about this class, used to generate documentation More...
 
- Private Member Functions inherited from Check
 Check (const std::string &aname)
 This constructor is used when registering the CheckClass. More...
 
 Check (const std::string &aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
 This constructor is used when running checks. More...
 
virtual ~Check ()
 
virtual void analyse (const Token *tokens, std::set< std::string > &result) const
 analyse code - must be thread safe More...
 
virtual void saveAnalysisData (const std::set< std::string > &data) const
 Save analysis data - the caller ensures thread safety. More...
 
virtual void runChecks (const Tokenizer *, const Settings *, ErrorLogger *)
 run checks, the token list is not simplified More...
 
const std::string & name () const
 class name, used to generate documentation More...
 
bool inconclusiveFlag () const
 
template<typename T , typename U >
void reportError (const Token *tok, const Severity::SeverityType severity, const T id, const U msg, bool inconclusive=false)
 report an error More...
 
template<typename T , typename U >
void reportError (const std::list< const Token * > &callstack, Severity::SeverityType severity, const T id, const U msg, bool inconclusive=false)
 report an error More...
 
- Private Member Functions inherited from CheckMemoryLeak
 CheckMemoryLeak (const Tokenizer *t, ErrorLogger *e, const Settings *s)
 
void memoryLeak (const Token *tok, const std::string &varname, AllocType alloctype)
 
AllocType getDeallocationType (const Token *tok, const std::string &varname) const
 Get type of deallocation at given position. More...
 
AllocType getDeallocationType (const Token *tok, unsigned int varid) const
 Get type of deallocation at given position. More...
 
AllocType getAllocationType (const Token *tok2, unsigned int varid, std::list< const Function * > *callstack=NULL) const
 Get type of allocation at given position. More...
 
bool isclass (const Token *tok, unsigned int varid) const
 Is a typename the name of a class? More...
 
void memleakError (const Token *tok, const std::string &varname) const
 Report that there is a memory leak (new/malloc/etc) More...
 
void resourceLeakError (const Token *tok, const std::string &varname) const
 Report that there is a resource leak (fopen/popen/etc) More...
 
void deallocDeallocError (const Token *tok, const std::string &varname) const
 Report error: deallocating a deallocated pointer. More...
 
void deallocuseError (const Token *tok, const std::string &varname) const
 
void mismatchSizeError (const Token *tok, const std::string &sz) const
 
void mismatchAllocDealloc (const std::list< const Token * > &callstack, const std::string &varname) const
 
void memleakUponReallocFailureError (const Token *tok, const std::string &varname) const
 
AllocType functionReturnType (const Function *func, std::list< const Function * > *callstack=NULL) const
 What type of allocated memory does the given function return? More...
 
const char * functionArgAlloc (const Function *func, unsigned int targetpar, AllocType &allocType) const
 Function allocates pointed-to argument (a la asprintf)? More...
 

Static Private Member Functions

static std::string myName ()
 
- Static Private Member Functions inherited from Check
static std::list< Check * > & instances ()
 List of registered check classes. More...
 
static void reportError (const ErrorLogger::ErrorMessage &errmsg)
 Write given error to errorlogger or to out stream in xml format. More...
 
- Static Private Member Functions inherited from CheckMemoryLeak
static AllocType getReallocationType (const Token *tok2, unsigned int varid)
 Get type of reallocation at given position. More...
 

Additional Inherited Members

- Private Types inherited from CheckMemoryLeak
enum  AllocType {
  No, Malloc, New, NewArray,
  File, Fd, Pipe, OtherMem,
  OtherRes, Many
}
 What type of allocation are used. More...
 

Detailed Description

Check class variables, variables that are allocated in the constructor should be deallocated in the destructor

Definition at line 340 of file checkmemoryleak.h.

Constructor & Destructor Documentation

CheckMemoryLeakInClass::CheckMemoryLeakInClass ( )
inline

Definition at line 342 of file checkmemoryleak.h.

CheckMemoryLeakInClass::CheckMemoryLeakInClass ( const Tokenizer tokenizr,
const Settings settings,
ErrorLogger errLog 
)
inline

Definition at line 345 of file checkmemoryleak.h.

Member Function Documentation

void CheckMemoryLeakInClass::check ( )
void CheckMemoryLeakInClass::checkPublicFunctions ( const Scope scope,
const Token classtok 
)
private
std::string CheckMemoryLeakInClass::classInfo ( ) const
inlineprivatevirtual

get information about this class, used to generate documentation

Implements Check.

Definition at line 378 of file checkmemoryleak.h.

void CheckMemoryLeakInClass::getErrorMessages ( ErrorLogger errorLogger,
const Settings settings 
) const
inlineprivatevirtual

get error messages

Implements Check.

Definition at line 368 of file checkmemoryleak.h.

References publicAllocationError(), and unsafeClassError().

static std::string CheckMemoryLeakInClass::myName ( )
inlinestaticprivate

Definition at line 374 of file checkmemoryleak.h.

void CheckMemoryLeakInClass::publicAllocationError ( const Token tok,
const std::string &  varname 
)
private

Definition at line 2443 of file checkmemoryleak.cpp.

References Check::reportError(), and Severity::warning.

Referenced by checkPublicFunctions(), and getErrorMessages().

void CheckMemoryLeakInClass::runSimplifiedChecks ( const Tokenizer tokenizer,
const Settings settings,
ErrorLogger errorLogger 
)
inlinevirtual

run checks, the token list is simplified

Implements Check.

Definition at line 349 of file checkmemoryleak.h.

References check(), and Tokenizer::isCPP().

void CheckMemoryLeakInClass::unsafeClassError ( const Token tok,
const std::string &  classname,
const std::string &  varname 
)
private

Definition at line 2397 of file checkmemoryleak.cpp.

References Check::reportError(), and Severity::style.

Referenced by getErrorMessages(), and variable().

void CheckMemoryLeakInClass::variable ( const Scope scope,
const Token tokVarname 
)
private

The documentation for this class was generated from the following files: