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

Check for leaks. More...

#include <checkleakautovar.h>

Inheritance diagram for CheckLeakAutoVar:
Check

Public Member Functions

 CheckLeakAutoVar ()
 This constructor is used when registering the CheckLeakAutoVar. More...
 
- 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 &, const 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

 CheckLeakAutoVar (const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
 This constructor is used when running checks. More...
 
void runChecks (const Tokenizer &tokenizer, ErrorLogger *errorLogger) override
 run checks, the token list is not simplified More...
 
void check ()
 check for leaks in all scopes More...
 
bool checkScope (const Token *const startToken, VarInfo &varInfo, std::set< int > notzero, nonneg int recursiveCount)
 check for leaks in a function scope More...
 
const TokencheckTokenInsideExpression (const Token *const tok, VarInfo &varInfo, bool inFuncCall=false)
 Check token inside expression. More...
 
void functionCall (const Token *tokName, const Token *tokOpeningPar, VarInfo &varInfo, const VarInfo::AllocInfo &allocation, const Library::AllocFunc *af)
 parse function call More...
 
void changeAllocStatus (VarInfo &varInfo, const VarInfo::AllocInfo &allocation, const Token *tok, const Token *arg)
 parse changes in allocation status More...
 
void changeAllocStatusIfRealloc (std::map< int, VarInfo::AllocInfo > &alloctype, const Token *fTok, const Token *retTok) const
 update allocation status if reallocation function More...
 
void ret (const Token *tok, VarInfo &varInfo, const bool isEndOfScope=false)
 return. More...
 
void leakIfAllocated (const Token *vartok, const VarInfo &varInfo)
 if variable is allocated then there is a leak More...
 
void leakError (const Token *tok, const std::string &varname, int type) const
 
void mismatchError (const Token *deallocTok, const Token *allocTok, const std::string &varname) const
 
void deallocUseError (const Token *tok, const std::string &varname) const
 
void deallocReturnError (const Token *tok, const Token *deallocTok, const std::string &varname)
 
void doubleFreeError (const Token *tok, const Token *prevFreeTok, const std::string &varname, int type)
 
void configurationInfo (const Token *tok, const std::pair< const Token *, VarInfo::Usage > &functionUsage)
 message: user configuration is needed to complete analysis More...
 
void getErrorMessages (ErrorLogger *errorLogger, const Settings *settings) const override
 get error messages More...
 
std::string classInfo () const override
 get information about this class, used to generate documentation More...
 

Static Private Member Functions

static std::string myName ()
 

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 {}
 

Detailed Description

Check for leaks.

Definition at line 108 of file checkleakautovar.h.

Constructor & Destructor Documentation

◆ CheckLeakAutoVar() [1/2]

CheckLeakAutoVar::CheckLeakAutoVar ( )
inline

This constructor is used when registering the CheckLeakAutoVar.

Definition at line 111 of file checkleakautovar.h.

◆ CheckLeakAutoVar() [2/2]

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

This constructor is used when running checks.

Definition at line 115 of file checkleakautovar.h.

Member Function Documentation

◆ changeAllocStatus()

void CheckLeakAutoVar::changeAllocStatus ( VarInfo varInfo,
const VarInfo::AllocInfo allocation,
const Token tok,
const Token arg 
)
private

◆ changeAllocStatusIfRealloc()

void CheckLeakAutoVar::changeAllocStatusIfRealloc ( std::map< int, VarInfo::AllocInfo > &  alloctype,
const Token fTok,
const Token retTok 
) const
private

◆ check()

void CheckLeakAutoVar::check ( )
private

◆ checkScope()

bool CheckLeakAutoVar::checkScope ( const Token *const  startToken,
VarInfo varInfo,
std::set< int >  notzero,
nonneg int  recursiveCount 
)
private

◆ checkTokenInsideExpression()

const Token * CheckLeakAutoVar::checkTokenInsideExpression ( const Token *const  tok,
VarInfo varInfo,
bool  inFuncCall = false 
)
private

◆ classInfo()

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

get information about this class, used to generate documentation

Implements Check.

Definition at line 174 of file checkleakautovar.h.

◆ configurationInfo()

void CheckLeakAutoVar::configurationInfo ( const Token tok,
const std::pair< const Token *, VarInfo::Usage > &  functionUsage 
)
private

message: user configuration is needed to complete analysis

Definition at line 184 of file checkleakautovar.cpp.

References Settings::checkLibrary, Library::getFunctionName(), information, Settings::library, Check::mSettings, and Check::reportError().

Referenced by getErrorMessages(), leakIfAllocated(), and ret().

◆ deallocReturnError()

void CheckLeakAutoVar::deallocReturnError ( const Token tok,
const Token deallocTok,
const std::string &  varname 
)
private

Definition at line 178 of file checkleakautovar.cpp.

References CWE672, error, normal, and Check::reportError().

Referenced by getErrorMessages(), and ret().

◆ deallocUseError()

void CheckLeakAutoVar::deallocUseError ( const Token tok,
const std::string &  varname 
) const
private

◆ doubleFreeError()

void CheckLeakAutoVar::doubleFreeError ( const Token tok,
const Token prevFreeTok,
const std::string &  varname,
int  type 
)
private

◆ functionCall()

void CheckLeakAutoVar::functionCall ( const Token tokName,
const Token tokOpeningPar,
VarInfo varInfo,
const VarInfo::AllocInfo allocation,
const Library::AllocFunc af 
)
private

◆ getErrorMessages()

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

get error messages

Implements Check.

Definition at line 163 of file checkleakautovar.h.

References configurationInfo(), deallocReturnError(), and doubleFreeError().

◆ leakError()

void CheckLeakAutoVar::leakError ( const Token tok,
const std::string &  varname,
int  type 
) const
private

◆ leakIfAllocated()

void CheckLeakAutoVar::leakIfAllocated ( const Token vartok,
const VarInfo varInfo 
)
private

if variable is allocated then there is a leak

Definition at line 1083 of file checkleakautovar.cpp.

References configurationInfo(), leakError(), Token::str(), and Token::varId().

Referenced by checkScope(), and functionCall().

◆ mismatchError()

void CheckLeakAutoVar::mismatchError ( const Token deallocTok,
const Token allocTok,
const std::string &  varname 
) const
private

◆ myName()

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

Definition at line 170 of file checkleakautovar.h.

◆ ret()

void CheckLeakAutoVar::ret ( const Token tok,
VarInfo varInfo,
const bool  isEndOfScope = false 
)
private

◆ runChecks()

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

run checks, the token list is not simplified

Implements Check.

Definition at line 118 of file checkleakautovar.h.

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


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