| 
    Cppcheck
    
   | 
 
Base class for memory leaks checking. More...
#include <checkmemoryleak.h>
  
Public Types | |
| enum | AllocType {  No , Malloc , New , NewArray , File , Fd , Pipe , OtherMem , OtherRes , Many }  | 
| What type of allocation are used.  More... | |
Public Member Functions | |
| 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 | |
| void | reportErr (const Token *tok, Severity severity, const std::string &id, const std::string &msg, const CWE &cwe) const | 
| Report error.  More... | |
| void | reportErr (const std::list< const Token * > &callstack, Severity severity, const std::string &id, const std::string &msg, const CWE &cwe) const | 
| Report error.  More... | |
Private Attributes | |
| const Tokenizer *const | mTokenizer_ | 
| For access to the tokens.  More... | |
| ErrorLogger *const | mErrorLogger_ | 
| ErrorLogger used to report errors.  More... | |
| const Settings *const | mSettings_ | 
| Enabled standards.  More... | |
Base class for memory leaks checking.
Definition at line 55 of file checkmemoryleak.h.
What type of allocation are used.
. the "Many" means that several types of allocation and deallocation are used
| Enumerator | |
|---|---|
| No | |
| Malloc | |
| New | |
| NewArray | |
| File | |
| Fd | |
| Pipe | |
| OtherMem | |
| OtherRes | |
| Many | |
Definition at line 95 of file checkmemoryleak.h.
      
  | 
  delete | 
      
  | 
  delete | 
      
  | 
  inline | 
Definition at line 91 of file checkmemoryleak.h.
| void CheckMemoryLeak::deallocuseError | ( | const Token * | tok, | 
| const std::string & | varname | ||
| ) | const | 
Definition at line 320 of file checkmemoryleak.cpp.
References CWE, error, and reportErr().
Referenced by CheckLeakAutoVar::deallocUseError(), and CheckMemoryLeakInFunction::getErrorMessages().
| CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType | ( | const Function * | func, | 
| std::list< const Function * > * | callstack = nullptr  | 
        ||
| ) | const | 
What type of allocated memory does the given function return?
Definition at line 330 of file checkmemoryleak.cpp.
References Token::astOperand1(), Token::astOperand2(), Scope::bodyEnd, Scope::bodyStart, Variable::declarationId(), findLambdaEndToken(), Function::functionScope, getAllocationType(), Function::hasBody(), Variable::isLocal(), Variable::isStatic(), Token::Match(), Token::next(), No, nonneg, and Token::variable().
Referenced by getAllocationType().
| CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType | ( | const Token * | tok2, | 
| nonneg int | varid, | ||
| std::list< const Function * > * | callstack = nullptr  | 
        ||
| ) | const | 
Get type of allocation at given position.
Definition at line 55 of file checkmemoryleak.cpp.
References Token::astOperand1(), Library::deallocId(), Fd, File, Token::function(), functionReturnType(), Library::getAllocId(), getReallocationType(), Settings::hasLib(), Token::isCpp(), Library::ismemory(), Token::isName(), Settings::library, Token::link(), Malloc, Token::Match(), mSettings_, New, NewArray, Token::next(), No, numberOfArguments(), Scope::numConstructors, OtherMem, OtherRes, Pipe, Token::simpleMatch(), Token::str(), Token::strAt(), Token::tokAt(), and Token::type().
Referenced by CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(), CheckMemoryLeakNoVar::checkForUnusedReturnValue(), CheckMemoryLeakInClass::checkPublicFunctions(), CheckMemoryLeakStructMember::checkStructVariable(), functionReturnType(), and CheckMemoryLeakInClass::variable().
| CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType | ( | const Token * | tok, | 
| nonneg int | varid | ||
| ) | const | 
Get type of deallocation at given position.
| tok | position | 
| varid | variable id | 
Definition at line 188 of file checkmemoryleak.cpp.
References Token::astOperand1(), Token::astOperand2(), Library::deallocId(), Fd, File, Library::getDeallocId(), Settings::hasLib(), Token::isCpp(), Library::ismemory(), Settings::library, Malloc, Token::Match(), mSettings_, New, NewArray, Token::next(), Token::nextArgument(), No, OtherMem, OtherRes, Pipe, Token::simpleMatch(), Token::str(), Token::strAt(), Token::tokAt(), and Token::varId().
Referenced by CheckMemoryLeakStructMember::checkStructVariable(), and CheckMemoryLeakInClass::variable().
| CheckMemoryLeak::AllocType CheckMemoryLeak::getReallocationType | ( | const Token * | tok2, | 
| nonneg int | varid | ||
| ) | const | 
Get type of reallocation at given position.
Definition at line 148 of file checkmemoryleak.cpp.
References Token::astOperand1(), Library::deallocId(), File, getArguments(), Library::getReallocFuncInfo(), Library::getReallocId(), Token::isCast(), Library::ismemory(), Token::isUnaryOp(), Settings::library, Token::link(), Malloc, Token::Match(), mSettings_, Token::next(), No, numberOfArguments(), OtherMem, OtherRes, Library::AllocFunc::reallocArg, and Token::str().
Referenced by CheckMemoryLeakInFunction::checkReallocUsage(), getAllocationType(), and isReopenStandardStream().
| bool CheckMemoryLeak::isOpenDevNull | ( | const Token * | tok | ) | const | 
Check if token opens /dev/null.
| tok | token to check | 
Definition at line 256 of file checkmemoryleak.cpp.
References getArguments(), Settings::hasLib(), mSettings_, numberOfArguments(), Token::simpleMatch(), and Token::str().
Referenced by CheckMemoryLeakNoVar::checkForUnusedReturnValue().
| bool CheckMemoryLeak::isReopenStandardStream | ( | const Token * | tok | ) | const | 
Check if token reopens a standard stream.
| tok | token to check | 
Definition at line 243 of file checkmemoryleak.cpp.
References File, getArguments(), getReallocationType(), Library::getReallocFuncInfo(), Settings::library, Token::Match(), mSettings_, numberOfArguments(), and Library::AllocFunc::reallocArg.
Referenced by CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(), and CheckMemoryLeakNoVar::checkForUnusedReturnValue().
| 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 302 of file checkmemoryleak.cpp.
References CWE, error, and reportErr().
Referenced by CheckMemoryLeakInFunction::getErrorMessages(), CheckLeakAutoVar::leakError(), and memoryLeak().
| void CheckMemoryLeak::memleakUponReallocFailureError | ( | const Token * | tok, | 
| const std::string & | reallocfunction, | ||
| const std::string & | varname | ||
| ) | const | 
Definition at line 307 of file checkmemoryleak.cpp.
References CWE, error, and reportErr().
Referenced by CheckMemoryLeakInFunction::checkReallocUsage(), and CheckMemoryLeakInFunction::getErrorMessages().
| void CheckMemoryLeak::memoryLeak | ( | const Token * | tok, | 
| const std::string & | varname, | ||
| AllocType | alloctype | ||
| ) | const | 
Definition at line 271 of file checkmemoryleak.cpp.
References Fd, File, memleakError(), OtherRes, Pipe, and resourceLeakError().
Referenced by CheckMemoryLeakStructMember::checkStructVariable().
| void CheckMemoryLeak::mismatchAllocDealloc | ( | const std::list< const Token * > & | callstack, | 
| const std::string & | varname | ||
| ) | const | 
Definition at line 325 of file checkmemoryleak.cpp.
References CWE, error, and reportErr().
Referenced by CheckMemoryLeakInFunction::getErrorMessages(), CheckLeakAutoVar::mismatchError(), and CheckMemoryLeakInClass::variable().
      
  | 
  delete | 
      
  | 
  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 | 
| cwe | cwe number | 
Definition at line 293 of file checkmemoryleak.cpp.
References Tokenizer::list, mErrorLogger_, mTokenizer_, normal, ErrorLogger::reportErr(), and Check::writeToErrorList().
      
  | 
  private | 
Report error.
Similar with the function Check::reportError
| tok | the token where the error occurs | 
| severity | the severity of the bug | 
| id | type of message | 
| msg | text | 
| cwe | cwe number | 
Definition at line 283 of file checkmemoryleak.cpp.
Referenced by deallocuseError(), memleakError(), memleakUponReallocFailureError(), mismatchAllocDealloc(), and resourceLeakError().
| 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 312 of file checkmemoryleak.cpp.
References CWE, error, and reportErr().
Referenced by CheckMemoryLeakInFunction::getErrorMessages(), CheckLeakAutoVar::leakError(), and memoryLeak().
      
  | 
  private | 
ErrorLogger used to report errors.
Definition at line 61 of file checkmemoryleak.h.
Referenced by reportErr().
      
  | 
  private | 
Enabled standards.
Definition at line 64 of file checkmemoryleak.h.
Referenced by getAllocationType(), getDeallocationType(), getReallocationType(), isOpenDevNull(), and isReopenStandardStream().
      
  | 
  private | 
For access to the tokens.
Definition at line 58 of file checkmemoryleak.h.
Referenced by reportErr().