| 
    Cppcheck
    
   | 
 
detect simple memory leaks (address not taken) More...
#include <checkmemoryleak.h>
  
Public Member Functions | |
| CheckMemoryLeakNoVar () | |
  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 &) | 
Private Member Functions | |
| CheckMemoryLeakNoVar (const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) | |
| void | runChecks (const Tokenizer &tokenizer, ErrorLogger *errorLogger) override | 
| run checks, the token list is not simplified  More... | |
| void | check () | 
| void | checkForUnreleasedInputArgument (const Scope *scope) | 
| Check if an input argument to a function is the return value of an allocation function like malloc(), and the function does not release it.  More... | |
| void | checkForUnusedReturnValue (const Scope *scope) | 
| Check if a call to an allocation function like malloc() is made and its return value is not assigned.  More... | |
| void | checkForUnsafeArgAlloc (const Scope *scope) | 
| Check if an exception could cause a leak in an argument constructed with shared_ptr/unique_ptr.  More... | |
| void | functionCallLeak (const Token *loc, const std::string &alloc, const std::string &functionCall) | 
| void | returnValueNotUsedError (const Token *tok, const std::string &alloc) | 
| void | unsafeArgAllocError (const Token *tok, const std::string &funcName, const std::string &ptrType, const std::string &objType) | 
| void | getErrorMessages (ErrorLogger *e, const Settings *settings) const override | 
| get error messages  More... | |
| std::string | classInfo () const override | 
| get information about this class, used to generate documentation  More... | |
  Private 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... | |
Static Private Member Functions | |
| static std::string | myName () | 
Friends | |
| class | TestMemleakNoVar | 
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 {} | 
  Private Types inherited from CheckMemoryLeak | |
| enum | AllocType {  No , Malloc , New , NewArray , File , Fd , Pipe , OtherMem , OtherRes , Many }  | 
| What type of allocation are used.  More... | |
detect simple memory leaks (address not taken)
Definition at line 307 of file checkmemoryleak.h.
      
  | 
  inline | 
Definition at line 311 of file checkmemoryleak.h.
      
  | 
  inlineprivate | 
Definition at line 314 of file checkmemoryleak.h.
      
  | 
  private | 
Definition at line 932 of file checkmemoryleak.cpp.
References checkForUnreleasedInputArgument(), checkForUnsafeArgAlloc(), checkForUnusedReturnValue(), SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Check::logChecker(), and Check::mTokenizer.
Referenced by runChecks().
      
  | 
  private | 
Check if an input argument to a function is the return value of an allocation function like malloc(), and the function does not release it.
| scope | The scope of the function to check. | 
Definition at line 958 of file checkmemoryleak.cpp.
References Token::astParent(), Scope::bodyEnd, Scope::bodyStart, Library::detectContainerOrIterator(), Token::expressionString(), functionCallLeak(), CheckMemoryLeak::getAllocationType(), getArguments(), Token::isCast(), Library::isLeakIgnore(), CheckMemoryLeak::isReopenStandardStream(), Token::isStandardType(), Settings::library, Token::Match(), Check::mSettings, CheckMemoryLeak::New, CheckMemoryLeak::NewArray, Token::next(), CheckMemoryLeak::No, Settings::platform, Library::podtype(), Token::simpleMatch(), Platform::sizeof_pointer, Token::type(), ValueType::typeSize(), and Variable::valueType().
Referenced by check().
      
  | 
  private | 
Check if an exception could cause a leak in an argument constructed with shared_ptr/unique_ptr.
| scope | The scope of the function to check. | 
Definition at line 1093 of file checkmemoryleak.cpp.
References Scope::bodyEnd, Scope::bodyStart, Settings::certainty, inconclusive, Function::isAttributeNothrow(), Tokenizer::isCPP(), SimpleEnableGroup< T >::isEnabled(), Settings::isPremiumEnabled(), Function::isThrow(), Token::link(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Token::nextArgument(), Settings::severity, Token::simpleMatch(), Token::str(), Token::strAt(), Token::tokAt(), unsafeArgAllocError(), and warning.
Referenced by check().
      
  | 
  private | 
Check if a call to an allocation function like malloc() is made and its return value is not assigned.
| scope | The scope of the function to check. | 
Definition at line 1031 of file checkmemoryleak.cpp.
References Token::astParent(), Scope::bodyEnd, Scope::bodyStart, Library::detectContainer(), Token::findmatch(), CheckMemoryLeak::getAllocationType(), Token::isCast(), CheckMemoryLeak::isOpenDevNull(), CheckMemoryLeak::isReopenStandardStream(), Token::isStandardType(), Settings::library, Token::link(), Token::Match(), Check::mSettings, Token::next(), CheckMemoryLeak::No, precedes(), returnValueNotUsedError(), Token::simpleMatch(), and Token::str().
Referenced by check().
      
  | 
  inlineoverrideprivatevirtual | 
get information about this class, used to generate documentation
Implements Check.
Definition at line 358 of file checkmemoryleak.h.
      
  | 
  private | 
Definition at line 1143 of file checkmemoryleak.cpp.
References CWE772, error, normal, and Check::reportError().
Referenced by checkForUnreleasedInputArgument(), and getErrorMessages().
      
  | 
  inlineoverrideprivatevirtual | 
get error messages
Implements Check.
Definition at line 347 of file checkmemoryleak.h.
References functionCallLeak(), returnValueNotUsedError(), and unsafeArgAllocError().
      
  | 
  inlinestaticprivate | 
Definition at line 354 of file checkmemoryleak.h.
      
  | 
  private | 
Definition at line 1148 of file checkmemoryleak.cpp.
References CWE771, error, normal, and Check::reportError().
Referenced by checkForUnusedReturnValue(), and getErrorMessages().
      
  | 
  inlineoverrideprivatevirtual | 
run checks, the token list is not simplified
Implements Check.
Definition at line 317 of file checkmemoryleak.h.
References check(), and Tokenizer::getSettings().
      
  | 
  private | 
Definition at line 1153 of file checkmemoryleak.cpp.
References CWE401, inconclusive, Check::reportError(), and warning.
Referenced by checkForUnsafeArgAlloc(), and getErrorMessages().
      
  | 
  friend | 
Definition at line 308 of file checkmemoryleak.h.