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)
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.
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
std::string classInfo () const
- Private Member Functions inherited from Check
 Check (const std::string &aname)
 This constructor is used when registering the CheckClass.
 Check (const std::string &aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
 This constructor is used when running checks.
virtual ~Check ()
virtual void runChecks (const Tokenizer *, const Settings *, ErrorLogger *)
 run checks, the token list is not simplified
virtual void runSimplifiedChecks (const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)=0
 run checks, the token list is simplified
virtual void getErrorMessages (ErrorLogger *errorLogger, const Settings *settings) const =0
 get error messages
const std::string & name () const
 class name, used to generate documentation
virtual std::string classInfo () const =0
 get information about this class, used to generate documentation
bool inconclusiveFlag () const
virtual FileInfogetFileInfo (const Tokenizer *tokenizer, const Settings *settings) const
virtual void analyseWholeProgram (const std::list< FileInfo * > &fileInfo, const Settings &settings, ErrorLogger &errorLogger)
template<typename T , typename U >
void reportError (const Token *tok, const Severity::SeverityType severity, const T id, const U msg)
 report an error
template<typename T , typename U >
void reportError (const Token *tok, const Severity::SeverityType severity, const T id, const U msg, unsigned int cwe, bool inconclusive)
 report an error
template<typename T , typename U >
void reportError (const std::list< const Token * > &callstack, Severity::SeverityType severity, const T id, const U msg)
 report an error
template<typename T , typename U >
void reportError (const std::list< const Token * > &callstack, Severity::SeverityType severity, const T id, const U msg, unsigned int cwe, bool inconclusive)
 report an error
- 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.
AllocType getDeallocationType (const Token *tok, unsigned int varid) const
 Get type of deallocation at given position.
AllocType getAllocationType (const Token *tok2, unsigned int varid, std::list< const Function * > *callstack=NULL) const
 Get type of allocation at given position.
bool isclass (const Token *tok, unsigned int varid) const
 Is a typename the name of a class?
void memleakError (const Token *tok, const std::string &varname) const
 Report that there is a memory leak (new/malloc/etc)
void resourceLeakError (const Token *tok, const std::string &varname) const
 Report that there is a resource leak (fopen/popen/etc)
void deallocDeallocError (const Token *tok, const std::string &varname) const
 Report error: deallocating a deallocated pointer.
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?
const char * functionArgAlloc (const Function *func, unsigned int targetpar, AllocType &allocType) const
 Function allocates pointed-to argument (a la asprintf)?

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.
static void reportError (const ErrorLogger::ErrorMessage &errmsg)
 Write given error to errorlogger or to out stream in xml format.
- Static Private Member Functions inherited from CheckMemoryLeak
static AllocType getReallocationType (const Token *tok2, unsigned int varid)
 Get type of reallocation at given position.

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 333 of file checkmemoryleak.h.

Constructor & Destructor Documentation

CheckMemoryLeakInClass::CheckMemoryLeakInClass ( )
inline

Definition at line 335 of file checkmemoryleak.h.

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

Definition at line 338 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
inlineprivate

Definition at line 371 of file checkmemoryleak.h.

void CheckMemoryLeakInClass::getErrorMessages ( ErrorLogger e,
const Settings settings 
) const
inlineprivate

Definition at line 361 of file checkmemoryleak.h.

References publicAllocationError(), and unsafeClassError().

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

Definition at line 367 of file checkmemoryleak.h.

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

Definition at line 2484 of file checkmemoryleak.cpp.

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

Referenced by checkPublicFunctions(), and getErrorMessages().

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

Definition at line 342 of file checkmemoryleak.h.

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

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

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