Cppcheck
Public Member Functions | Private Member Functions | Static Private Member Functions | Friends | List of all members
CheckMemoryLeakStructMember Class Reference

detect simple memory leaks for struct members More...

#include <checkmemoryleak.h>

Inheritance diagram for CheckMemoryLeakStructMember:
Check CheckMemoryLeak

Public Member Functions

 CheckMemoryLeakStructMember ()
 
- Public Member Functions inherited from Check
 Check (const std::string &aname)
 This constructor is used when registering the CheckClass. More...
 
virtual ~Check ()
 
 Check (const Check &)=delete
 
Checkoperator= (const Check &)=delete
 
const std::string & name () const
 class name, used to generate documentation More...
 
virtual FileInfogetFileInfo (const Tokenizer *tokenizer, const Settings *settings) const
 
virtual FileInfoloadFileInfoFromXml (const tinyxml2::XMLElement *xmlElement) const
 
virtual bool analyseWholeProgram (const CTU::FileInfo *ctu, const std::list< FileInfo * > &fileInfo, const Settings &, ErrorLogger &)
 

Private Member Functions

 CheckMemoryLeakStructMember (const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
 
void runChecks (const Tokenizer &tokenizer, ErrorLogger *errorLogger) override
 run checks, the token list is not simplified More...
 
void check ()
 
bool isMalloc (const Variable *variable) const
 Is local variable allocated with malloc? More...
 
void checkStructVariable (const Variable *const variable) const
 
void getErrorMessages (ErrorLogger *, const Settings *) const override
 get error messages More...
 
std::string classInfo () const override
 get information about this class, used to generate documentation More...
 
- Private Member Functions inherited from CheckMemoryLeak
 CheckMemoryLeak ()=delete
 
 CheckMemoryLeak (const CheckMemoryLeak &)=delete
 
CheckMemoryLeakoperator= (const CheckMemoryLeak &)=delete
 
 CheckMemoryLeak (const Tokenizer *t, ErrorLogger *e, const Settings *s)
 
void memoryLeak (const Token *tok, const std::string &varname, AllocType alloctype) const
 
AllocType getDeallocationType (const Token *tok, nonneg int varid) const
 Get type of deallocation at given position. More...
 
AllocType getAllocationType (const Token *tok2, nonneg int varid, std::list< const Function * > *callstack=nullptr) const
 Get type of allocation at given position. More...
 
AllocType getReallocationType (const Token *tok2, nonneg int varid) const
 Get type of reallocation at given position. More...
 
bool isReopenStandardStream (const Token *tok) const
 Check if token reopens a standard stream. More...
 
bool isOpenDevNull (const Token *tok) const
 Check if token opens /dev/null. 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 deallocuseError (const Token *tok, const std::string &varname) const
 
void mismatchAllocDealloc (const std::list< const Token * > &callstack, const std::string &varname) const
 
void memleakUponReallocFailureError (const Token *tok, const std::string &reallocfunction, const std::string &varname) const
 
AllocType functionReturnType (const Function *func, std::list< const Function * > *callstack=nullptr) const
 What type of allocated memory does the given function return? More...
 

Static Private Member Functions

static std::string myName ()
 

Friends

class TestMemleakStructMember
 

Additional Inherited Members

- Static Public Member Functions inherited from Check
static std::list< Check * > & instances ()
 List of registered check classes. More...
 
static void writeToErrorList (const ErrorMessage &errmsg)
 Write given error to stdout in xml format. More...
 
- Protected Member Functions inherited from Check
 Check (std::string aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
 This constructor is used when running checks. More...
 
void reportError (const Token *tok, const Severity severity, const std::string &id, const std::string &msg)
 report an error More...
 
void reportError (const Token *tok, const Severity severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty)
 report an error More...
 
void reportError (const std::list< const Token * > &callstack, Severity severity, const std::string &id, const std::string &msg)
 report an error More...
 
void reportError (const std::list< const Token * > &callstack, Severity severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty)
 report an error More...
 
void reportError (const ErrorPath &errorPath, Severity severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty)
 
void logChecker (const char id[])
 log checker More...
 
ErrorPath getErrorPath (const Token *errtok, const ValueFlow::Value *value, std::string bug) const
 
bool wrongData (const Token *tok, const char *str)
 Use WRONG_DATA in checkers when you check for wrong data. More...
 
- Static Protected Member Functions inherited from Check
static std::string getMessageId (const ValueFlow::Value &value, const char id[])
 
- Protected Attributes inherited from Check
const Tokenizer *const mTokenizer {}
 
const Settings *const mSettings {}
 
ErrorLogger *const mErrorLogger {}
 
- 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

detect simple memory leaks for struct members

Definition at line 270 of file checkmemoryleak.h.

Constructor & Destructor Documentation

◆ CheckMemoryLeakStructMember() [1/2]

CheckMemoryLeakStructMember::CheckMemoryLeakStructMember ( )
inline

Definition at line 274 of file checkmemoryleak.h.

◆ CheckMemoryLeakStructMember() [2/2]

CheckMemoryLeakStructMember::CheckMemoryLeakStructMember ( const Tokenizer tokenizer,
const Settings settings,
ErrorLogger errorLogger 
)
inlineprivate

Definition at line 277 of file checkmemoryleak.h.

Member Function Documentation

◆ check()

void CheckMemoryLeakStructMember::check ( )
private

◆ checkStructVariable()

void CheckMemoryLeakStructMember::checkStructVariable ( const Variable *const  variable) const
private

◆ classInfo()

std::string CheckMemoryLeakStructMember::classInfo ( ) const
inlineoverrideprivatevirtual

get information about this class, used to generate documentation

Implements Check.

Definition at line 298 of file checkmemoryleak.h.

◆ getErrorMessages()

void CheckMemoryLeakStructMember::getErrorMessages ( ErrorLogger errorLogger,
const Settings settings 
) const
inlineoverrideprivatevirtual

get error messages

Implements Check.

Definition at line 292 of file checkmemoryleak.h.

◆ isMalloc()

bool CheckMemoryLeakStructMember::isMalloc ( const Variable variable) const
private

◆ myName()

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

Definition at line 294 of file checkmemoryleak.h.

◆ runChecks()

void CheckMemoryLeakStructMember::runChecks ( const Tokenizer ,
ErrorLogger  
)
inlineoverrideprivatevirtual

run checks, the token list is not simplified

Implements Check.

Definition at line 280 of file checkmemoryleak.h.

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

Friends And Related Function Documentation

◆ TestMemleakStructMember

friend class TestMemleakStructMember
friend

Definition at line 271 of file checkmemoryleak.h.


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