Cppcheck
|
CheckMemoryLeakInFunction detects when a function variable is allocated but not deallocated properly. More...
#include <checkmemoryleak.h>
Public Member Functions | |
CheckMemoryLeakInFunction () | |
This constructor is used when registering this class. 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 | |
Check & | operator= (const Check &)=delete |
const std::string & | name () const |
class name, used to generate documentation More... | |
virtual FileInfo * | getFileInfo (const Tokenizer &, const Settings &) const |
virtual FileInfo * | loadFileInfoFromXml (const tinyxml2::XMLElement *xmlElement) const |
virtual bool | analyseWholeProgram (const CTU::FileInfo *ctu, const std::list< FileInfo * > &fileInfo, const Settings &, ErrorLogger &) |
Public Member Functions inherited from CheckMemoryLeak | |
CheckMemoryLeak ()=delete | |
CheckMemoryLeak (const CheckMemoryLeak &)=delete | |
CheckMemoryLeak & | operator= (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... | |
Private Member Functions | |
CheckMemoryLeakInFunction (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 | checkReallocUsage () |
Checking for a memory leak caused by improper realloc usage. More... | |
void | getErrorMessages (ErrorLogger *e, const Settings *settings) const override |
Report all possible errors (for the –errorlist) More... | |
std::string | classInfo () const override |
Get class information (–doc) More... | |
Static Private Member Functions | |
static std::string | myName () |
Get name of class (–doc) More... | |
Friends | |
class | TestMemleakInFunction |
Additional Inherited Members | |
Public Types inherited from CheckMemoryLeak | |
enum | AllocType { No , Malloc , New , NewArray , File , Fd , Pipe , OtherMem , OtherRes , Many } |
What type of allocation are used. More... | |
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 {} |
CheckMemoryLeakInFunction detects when a function variable is allocated but not deallocated properly.
The checking is done by looking at each function variable separately. By repeating these 4 steps over and over:
Definition at line 167 of file checkmemoryleak.h.
|
inline |
This constructor is used when registering this class.
Definition at line 172 of file checkmemoryleak.h.
|
inlineprivate |
This constructor is used when running checks.
Definition at line 176 of file checkmemoryleak.h.
|
private |
Checking for a memory leak caused by improper realloc usage.
Definition at line 428 of file checkmemoryleak.cpp.
References Library::AllocFunc::arg, Token::astOperand1(), Token::astOperand2(), Token::astParent(), Scope::bodyEnd, Scope::bodyStart, Token::findmatch(), SymbolDatabase::functionScopes, getArguments(), Token::getKnownIntValue(), CheckMemoryLeak::getReallocationType(), Library::getReallocFuncInfo(), Tokenizer::getSymbolDatabase(), Token::hasKnownIntValue(), Token::isCast(), Library::isnotnoreturn(), Tokenizer::isScopeNoReturn(), Token::isUnaryOp(), Settings::library, Token::linkAt(), Check::logChecker(), CheckMemoryLeak::Malloc, Token::Match(), CheckMemoryLeak::memleakUponReallocFailureError(), Check::mSettings, Check::mTokenizer, Token::next(), notvar(), CheckMemoryLeak::OtherMem, Library::AllocFunc::reallocArg, Token::simpleMatch(), Token::str(), Token::tokAt(), and Token::varId().
Referenced by runChecks().
|
inlineoverrideprivatevirtual |
Get class information (–doc)
Implements Check.
Definition at line 212 of file checkmemoryleak.h.
|
inlineoverrideprivatevirtual |
Report all possible errors (for the –errorlist)
Implements Check.
Definition at line 190 of file checkmemoryleak.h.
References CheckMemoryLeak::deallocuseError(), CheckMemoryLeak::memleakError(), CheckMemoryLeak::memleakUponReallocFailureError(), CheckMemoryLeak::mismatchAllocDealloc(), and CheckMemoryLeak::resourceLeakError().
|
inlinestaticprivate |
|
inlineoverrideprivatevirtual |
run checks, the token list is not simplified
Implements Check.
Definition at line 179 of file checkmemoryleak.h.
References checkReallocUsage(), and Tokenizer::getSettings().
|
friend |
Definition at line 168 of file checkmemoryleak.h.