Cppcheck
|
Check class variables, variables that are allocated in the constructor should be deallocated in the destructor More...
#include <checkmemoryleak.h>
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 |
![]() | |
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 | |
virtual FileInfo * | getFileInfo (const Tokenizer *tokenizer, const Settings *settings) const |
virtual FileInfo * | loadFileInfoFromXml (const tinyxml2::XMLElement *xmlElement) const |
virtual bool | 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, const CWE &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, const CWE &cwe, bool inconclusive) |
report an error | |
void | reportError (const ErrorPath &errorPath, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, bool inconclusive) |
ErrorPath | getErrorPath (const Token *errtok, const ValueFlow::Value *value, const std::string &bug) const |
bool | wrongData (const Token *tok, bool condition, const char *str) |
Use WRONG_DATA in checkers when you check for wrong data. | |
![]() | |
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, unsigned int varid) const |
Get type of deallocation at given position. | |
AllocType | getAllocationType (const Token *tok2, unsigned int varid, std::list< const Function * > *callstack=nullptr) 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=nullptr) 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 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 AllocType | getReallocationType (const Token *tok2, unsigned int varid) |
Get type of reallocation at given position. |
Additional Inherited Members | |
![]() | |
enum | AllocType { No, Malloc, New, NewArray, File, Fd, Pipe, OtherMem, OtherRes, Many } |
What type of allocation are used. More... |
Check class variables, variables that are allocated in the constructor should be deallocated in the destructor
Definition at line 330 of file checkmemoryleak.h.
|
inline |
Definition at line 332 of file checkmemoryleak.h.
|
inline |
Definition at line 335 of file checkmemoryleak.h.
void CheckMemoryLeakInClass::check | ( | ) |
Definition at line 2248 of file checkmemoryleak.cpp.
References Check::_tokenizer, checkPublicFunctions(), SymbolDatabase::classAndStructScopes, Tokenizer::getSymbolDatabase(), Token::isStandardType(), variable(), and Scope::varlist.
Referenced by runSimplifiedChecks().
|
private |
Public functions: possible double-allocation.
Definition at line 2396 of file checkmemoryleak.cpp.
References Check::_settings, Scope::className, Function::eFunction, Function::eOperatorEqual, Scope::functionList, CheckMemoryLeak::getAllocationType(), Settings::isEnabled(), Token::Match(), CheckMemoryLeak::No, Public, publicAllocationError(), Token::str(), Token::strAt(), Token::tokAt(), Token::varId(), and Settings::WARNING.
Referenced by check().
|
inlineprivate |
Definition at line 368 of file checkmemoryleak.h.
|
inlineprivate |
Definition at line 358 of file checkmemoryleak.h.
References publicAllocationError(), and unsafeClassError().
|
inlinestaticprivate |
Definition at line 364 of file checkmemoryleak.h.
|
private |
Definition at line 2428 of file checkmemoryleak.cpp.
References CWE398, Check::reportError(), and Severity::warning.
Referenced by checkPublicFunctions(), and getErrorMessages().
|
inline |
Definition at line 339 of file checkmemoryleak.h.
References check(), and Tokenizer::isCPP().
|
private |
Definition at line 2383 of file checkmemoryleak.cpp.
References Check::_settings, CWE398, Settings::isEnabled(), Check::reportError(), Settings::STYLE, and Severity::style.
Referenced by getErrorMessages(), and variable().
Definition at line 2273 of file checkmemoryleak.cpp.
References Check::_settings, Scope::className, Scope::functionList, CheckMemoryLeak::getAllocationType(), CheckMemoryLeak::getDeallocationType(), Tokenizer::isCPP(), CheckMemoryLeak::Many, Token::Match(), CheckMemoryLeak::mismatchAllocDealloc(), Token::next(), CheckMemoryLeak::No, Token::str(), CheckMemoryLeakInFunction::test_white_list(), CheckMemoryLeak::tokenizer, unsafeClassError(), and Token::varId().
Referenced by check().