|
Cppcheck
|
Base class for memory leaks checking. More...
#include <checkmemoryleak.h>
Public Types | |
| enum | AllocType { No, Malloc, gMalloc, New, NewArray, File, Fd, Pipe, Dir, Many } |
| What type of allocation are used. More... | |
Public Member Functions | |
| CheckMemoryLeak (const Tokenizer *t, ErrorLogger *e, const Standards &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. | |
| AllocType | getReallocationType (const Token *tok2, unsigned int varid) const |
| Get type of reallocation 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)? | |
Private Member Functions | |
| CheckMemoryLeak () | |
| Disable the default constructors. | |
| CheckMemoryLeak (const CheckMemoryLeak &) | |
| Disable the default constructors. | |
| void | operator= (const CheckMemoryLeak &) |
| disable assignment operator | |
| void | reportErr (const Token *location, Severity::SeverityType severity, const std::string &id, const std::string &msg) const |
| Report error. | |
| void | reportErr (const std::list< const Token * > &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg) const |
| Report error. | |
Private Attributes | |
| const Tokenizer *const | tokenizer |
| For access to the tokens. | |
| ErrorLogger *const | errorLogger |
| ErrorLogger used to report errors. | |
| const Standards & | standards |
| Enabled standards. | |
Base class for memory leaks checking.
Definition at line 52 of file checkmemoryleak.h.
What type of allocation are used.
. the "Many" means that several types of allocation and deallocation are used
Definition at line 96 of file checkmemoryleak.h.
| CheckMemoryLeak::CheckMemoryLeak | ( | ) | [private] |
Disable the default constructors.
| CheckMemoryLeak::CheckMemoryLeak | ( | const CheckMemoryLeak & | ) | [private] |
Disable the default constructors.
| CheckMemoryLeak::CheckMemoryLeak | ( | const Tokenizer * | t, |
| ErrorLogger * | e, | ||
| const Standards & | s | ||
| ) | [inline] |
Definition at line 91 of file checkmemoryleak.h.
| void CheckMemoryLeak::deallocDeallocError | ( | const Token * | tok, |
| const std::string & | varname | ||
| ) | const |
Report error: deallocating a deallocated pointer.
| tok | token where error occurs |
| varname | name of variable |
Definition at line 402 of file checkmemoryleak.cpp.
References Severity::error, and reportErr().
Referenced by CheckMemoryLeakInFunction::checkScope(), and CheckMemoryLeakInFunction::getErrorMessages().
| void CheckMemoryLeak::deallocuseError | ( | const Token * | tok, |
| const std::string & | varname | ||
| ) | const |
Definition at line 407 of file checkmemoryleak.cpp.
References Severity::error, and reportErr().
Referenced by CheckMemoryLeakInFunction::checkScope(), CheckLeakAutoVar::deallocUseError(), and CheckMemoryLeakInFunction::getErrorMessages().
| const char * CheckMemoryLeak::functionArgAlloc | ( | const Function * | func, |
| unsigned int | targetpar, | ||
| AllocType & | allocType | ||
| ) | const |
Function allocates pointed-to argument (a la asprintf)?
Definition at line 486 of file checkmemoryleak.cpp.
References Function::argumentList, Scope::classEnd, Scope::classStart, Function::functionScope, getAllocationType(), getReallocationType(), Token::Match(), Token::next(), No, Token::previous(), Token::str(), Token::tokAt(), and Token::varId().
Referenced by CheckMemoryLeakInFunction::call_func().
| CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType | ( | const Function * | func, |
| std::list< const Function * > * | callstack = NULL |
||
| ) | const |
What type of allocated memory does the given function return?
Definition at line 422 of file checkmemoryleak.cpp.
References Scope::classEnd, Scope::classStart, Function::functionScope, getAllocationType(), Tokenizer::getSymbolDatabase(), SymbolDatabase::getVariableFromVarId(), Function::hasBody, Variable::isLocal(), Variable::isStatic(), Token::Match(), Token::next(), No, and tokenizer.
Referenced by getAllocationType().
| CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType | ( | const Token * | tok2, |
| unsigned int | varid, | ||
| std::list< const Function * > * | callstack = NULL |
||
| ) | const |
Get type of allocation at given position.
Definition at line 127 of file checkmemoryleak.cpp.
References countParameters(), Dir, Fd, File, Token::findmatch(), Token::function(), functionReturnType(), gMalloc, Token::isName(), Token::link(), Malloc, Token::Match(), New, NewArray, Token::next(), No, Pipe, Standards::posix, Token::simpleMatch(), standards, Token::str(), Token::tokAt(), tokenizer, Tokenizer::tokens(), and Token::varId().
Referenced by CheckMemoryLeakInFunction::call_func(), CheckMemoryLeakNoVar::check(), CheckMemoryLeakInClass::checkPublicFunctions(), functionArgAlloc(), functionReturnType(), CheckMemoryLeakInFunction::getcode(), and CheckMemoryLeakInClass::variable().
| CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType | ( | const Token * | tok, |
| const std::string & | varname | ||
| ) | const |
Get type of deallocation at given position.
| tok | position |
| varname | variable name |
Definition at line 308 of file checkmemoryleak.cpp.
References Dir, Fd, File, gMalloc, Malloc, Token::Match(), New, NewArray, No, Pipe, and Token::simpleMatch().
Referenced by CheckMemoryLeakInFunction::call_func(), CheckMemoryLeakInFunction::getcode(), and CheckMemoryLeakInClass::variable().
| CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType | ( | const Token * | tok, |
| unsigned int | varid | ||
| ) | const |
Get type of deallocation at given position.
| tok | position |
| varid | variable id |
Definition at line 266 of file checkmemoryleak.cpp.
References Dir, Fd, File, gMalloc, Malloc, Token::Match(), New, NewArray, Token::next(), No, Pipe, Token::simpleMatch(), and Token::str().
| CheckMemoryLeak::AllocType CheckMemoryLeak::getReallocationType | ( | const Token * | tok2, |
| unsigned int | varid | ||
| ) | const |
Get type of reallocation at given position.
Definition at line 241 of file checkmemoryleak.cpp.
References gMalloc, Token::link(), Malloc, Token::Match(), Token::next(), No, and Token::str().
Referenced by CheckMemoryLeakInFunction::call_func(), functionArgAlloc(), and CheckMemoryLeakInFunction::getcode().
| bool CheckMemoryLeak::isclass | ( | const Token * | tok, |
| unsigned int | varid | ||
| ) | const |
Is a typename the name of a class?
| tok | type token |
| varid | variable id |
Definition at line 107 of file checkmemoryleak.cpp.
References Type::derivedFrom, Tokenizer::getSymbolDatabase(), SymbolDatabase::getVariableFromVarId(), Token::isStandardType(), Type::needInitialization, Scope::numConstructors, tokenizer, Type::True, Variable::type(), Variable::typeScope(), and Scope::varlist.
Referenced by CheckMemoryLeakInFunction::getcode().
| void CheckMemoryLeak::memleakError | ( | const Token * | tok, |
| const std::string & | varname | ||
| ) | const |
Report that there is a memory leak (new/malloc/etc)
| tok | token where memory is leaked |
| varname | name of variable |
Definition at line 384 of file checkmemoryleak.cpp.
References Severity::error, and reportErr().
Referenced by CheckMemoryLeakInFunction::getErrorMessages(), CheckLeakAutoVar::leakError(), and memoryLeak().
| void CheckMemoryLeak::memleakUponReallocFailureError | ( | const Token * | tok, |
| const std::string & | varname | ||
| ) | const |
Definition at line 389 of file checkmemoryleak.cpp.
References Severity::error, and reportErr().
Referenced by CheckMemoryLeakInFunction::checkReallocUsage(), and CheckMemoryLeakInFunction::getErrorMessages().
| void CheckMemoryLeak::memoryLeak | ( | const Token * | tok, |
| const std::string & | varname, | ||
| AllocType | alloctype | ||
| ) |
Definition at line 351 of file checkmemoryleak.cpp.
References Dir, Fd, File, memleakError(), Pipe, and resourceLeakError().
Referenced by CheckMemoryLeakInFunction::checkScope(), and CheckMemoryLeakStructMember::checkStructVariable().
| void CheckMemoryLeak::mismatchAllocDealloc | ( | const std::list< const Token * > & | callstack, |
| const std::string & | varname | ||
| ) | const |
Definition at line 417 of file checkmemoryleak.cpp.
References Severity::error, and reportErr().
Referenced by CheckMemoryLeakInFunction::getcode(), CheckMemoryLeakInFunction::getErrorMessages(), CheckLeakAutoVar::mismatchError(), and CheckMemoryLeakInClass::variable().
| void CheckMemoryLeak::mismatchSizeError | ( | const Token * | tok, |
| const std::string & | sz | ||
| ) | const |
Definition at line 412 of file checkmemoryleak.cpp.
References Severity::error, and reportErr().
Referenced by CheckMemoryLeakInFunction::getcode(), and CheckMemoryLeakInFunction::getErrorMessages().
| void CheckMemoryLeak::operator= | ( | const CheckMemoryLeak & | ) | [private] |
disable assignment operator
| void CheckMemoryLeak::reportErr | ( | const Token * | location, |
| Severity::SeverityType | severity, | ||
| const std::string & | id, | ||
| const std::string & | msg | ||
| ) | const [private] |
Report error.
Similar with the function Check::reportError
| location | the token where the error occurs |
| severity | the severity of the bug |
| id | type of message |
| msg | text |
Definition at line 364 of file checkmemoryleak.cpp.
Referenced by deallocDeallocError(), deallocuseError(), memleakError(), memleakUponReallocFailureError(), mismatchAllocDealloc(), mismatchSizeError(), and resourceLeakError().
| void CheckMemoryLeak::reportErr | ( | const std::list< const Token * > & | callstack, |
| Severity::SeverityType | severity, | ||
| const std::string & | id, | ||
| const std::string & | msg | ||
| ) | const [private] |
Report error.
Similar with the function Check::reportError
| callstack | callstack of error |
| severity | the severity of the bug |
| id | type of message |
| msg | text |
Definition at line 374 of file checkmemoryleak.cpp.
References errorLogger, Tokenizer::list, ErrorLogger::reportErr(), Check::reportError(), and tokenizer.
| void CheckMemoryLeak::resourceLeakError | ( | const Token * | tok, |
| const std::string & | varname | ||
| ) | const |
Report that there is a resource leak (fopen/popen/etc)
| tok | token where resource is leaked |
| varname | name of variable |
Definition at line 394 of file checkmemoryleak.cpp.
References Severity::error, and reportErr().
Referenced by CheckMemoryLeakInFunction::getErrorMessages(), CheckLeakAutoVar::leakError(), and memoryLeak().
ErrorLogger* const CheckMemoryLeak::errorLogger [private] |
ErrorLogger used to report errors.
Definition at line 58 of file checkmemoryleak.h.
Referenced by reportErr().
const Standards& CheckMemoryLeak::standards [private] |
Enabled standards.
Definition at line 61 of file checkmemoryleak.h.
Referenced by getAllocationType().
const Tokenizer* const CheckMemoryLeak::tokenizer [private] |
For access to the tokens.
Definition at line 55 of file checkmemoryleak.h.
Referenced by functionReturnType(), getAllocationType(), isclass(), and reportErr().
1.7.6.1