Cppcheck
|
#include <checkleakautovar.h>
Public Member Functions | |
CheckLeakAutoVar () | |
This constructor is used when registering the CheckLeakAutoVar. 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 &) |
Private Member Functions | |
CheckLeakAutoVar (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 | check () |
check for leaks in all scopes More... | |
bool | checkScope (const Token *const startToken, VarInfo &varInfo, std::set< int > notzero, nonneg int recursiveCount) |
check for leaks in a function scope More... | |
const Token * | checkTokenInsideExpression (const Token *const tok, VarInfo &varInfo, bool inFuncCall=false) |
Check token inside expression. More... | |
void | functionCall (const Token *tokName, const Token *tokOpeningPar, VarInfo &varInfo, const VarInfo::AllocInfo &allocation, const Library::AllocFunc *af) |
parse function call More... | |
void | changeAllocStatus (VarInfo &varInfo, const VarInfo::AllocInfo &allocation, const Token *tok, const Token *arg) |
parse changes in allocation status More... | |
void | changeAllocStatusIfRealloc (std::map< int, VarInfo::AllocInfo > &alloctype, const Token *fTok, const Token *retTok) const |
update allocation status if reallocation function More... | |
void | ret (const Token *tok, VarInfo &varInfo, const bool isEndOfScope=false) |
return. More... | |
void | leakIfAllocated (const Token *vartok, const VarInfo &varInfo) |
if variable is allocated then there is a leak More... | |
void | leakError (const Token *tok, const std::string &varname, int type) const |
void | mismatchError (const Token *deallocTok, const Token *allocTok, const std::string &varname) const |
void | deallocUseError (const Token *tok, const std::string &varname) const |
void | deallocReturnError (const Token *tok, const Token *deallocTok, const std::string &varname) |
void | doubleFreeError (const Token *tok, const Token *prevFreeTok, const std::string &varname, int type) |
void | configurationInfo (const Token *tok, const std::pair< const Token *, VarInfo::Usage > &functionUsage) |
message: user configuration is needed to complete analysis More... | |
void | getErrorMessages (ErrorLogger *errorLogger, const Settings *settings) const override |
get error messages More... | |
std::string | classInfo () const override |
get information about this class, used to generate documentation More... | |
Static Private Member Functions | |
static std::string | myName () |
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 {} |
Check for leaks.
Definition at line 108 of file checkleakautovar.h.
|
inline |
This constructor is used when registering the CheckLeakAutoVar.
Definition at line 111 of file checkleakautovar.h.
|
inlineprivate |
This constructor is used when running checks.
Definition at line 115 of file checkleakautovar.h.
|
private |
parse changes in allocation status
Definition at line 918 of file checkleakautovar.cpp.
References VarInfo::AllocInfo::allocTok, Token::astTop(), doubleFreeError(), mismatchError(), Token::previous(), Token::simpleMatch(), VarInfo::AllocInfo::status, Token::str(), VarInfo::AllocInfo::type, and Token::varId().
Referenced by checkScope(), and functionCall().
|
private |
update allocation status if reallocation function
Definition at line 897 of file checkleakautovar.cpp.
References VarInfo::AllocInfo::allocTok, Library::AllocFunc::arg, getArguments(), Library::getReallocFuncInfo(), Library::AllocFunc::groupId, Settings::library, mismatchError(), Check::mSettings, numberOfArguments(), Library::AllocFunc::reallocArg, VarInfo::AllocInfo::reallocedFromType, VarInfo::AllocInfo::status, Token::str(), VarInfo::AllocInfo::type, and Token::varId().
Referenced by checkScope().
|
private |
check for leaks in all scopes
Definition at line 209 of file checkleakautovar.cpp.
References Scope::bodyStart, checkScope(), Settings::clang, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Scope::hasInlineOrLambdaFunction(), Check::logChecker(), Check::mSettings, and Check::mTokenizer.
Referenced by runChecks().
|
private |
check for leaks in a function scope
Definition at line 307 of file checkleakautovar.cpp.
References alloc_failed_conds, alloc_success_conds, VarInfo::AllocInfo::allocTok, Library::AllocFunc::arg, astIsVariableComparison(), Token::astOperand1(), Token::astOperand2(), Token::astParent(), Scope::bodyEnd, Scope::bodyStart, changeAllocStatus(), changeAllocStatusIfRealloc(), checkTokenInsideExpression(), Scope::eTry, Token::findmatch(), Token::findsimplematch(), Token::function(), functionCall(), Library::getAllocFuncInfo(), Library::getDeallocFuncInfo(), Library::getFunctionName(), Library::AllocFunc::groupId, Token::isCast(), Token::isCpp(), Scope::isExecutable(), isFunctionCall(), Library::isLeakIgnore(), isLocalVarNoAutoDealloc(), Token::isName(), isPointerReleased(), Tokenizer::isScopeNoReturn(), Library::isSmartPointer(), isUnevaluated(), Token::isUpperCaseName(), Library::isUse(), isVarTokComparison(), isVarUsedInTree(), leakIfAllocated(), Settings::library, InternalError::LIMIT, Token::link(), Token::linkAt(), Token::Match(), Check::mSettings, Check::mTokenizer, Scope::nestedIn, NEW, NEW_ARRAY, Token::next(), none, nonneg, Token::previous(), ret(), Token::simpleMatch(), VarInfo::AllocInfo::status, Token::str(), Token::strAt(), succeeds(), MathLib::toBigNumber(), Token::tokAt(), VarInfo::AllocInfo::type, Scope::type, Token::type(), Token::varId(), and visitAstNodes().
Referenced by check().
|
private |
Check token inside expression.
tok | token inside expression. |
varInfo | Variable info |
Definition at line 829 of file checkleakautovar.cpp.
References Token::astOperand1(), Token::astOperand2(), Token::astParent(), deallocUseError(), functionCall(), Library::getDeallocFuncInfo(), getTokenArgumentFunction(), Library::AllocFunc::groupId, Token::isCast(), isCPPCast(), isFunctionCall(), CheckNullPointer::isPointerDeRef(), Settings::library, Token::link(), Token::Match(), Check::mSettings, Token::previous(), Library::returnValue(), Token::simpleMatch(), startsWith(), VarInfo::AllocInfo::status, Token::str(), Token::tokAt(), VarInfo::AllocInfo::type, and Token::varId().
Referenced by checkScope(), and functionCall().
|
inlineoverrideprivatevirtual |
get information about this class, used to generate documentation
Implements Check.
Definition at line 174 of file checkleakautovar.h.
|
private |
message: user configuration is needed to complete analysis
Definition at line 184 of file checkleakautovar.cpp.
References Settings::checkLibrary, Library::getFunctionName(), information, Settings::library, Check::mSettings, and Check::reportError().
Referenced by getErrorMessages(), leakIfAllocated(), and ret().
|
private |
Definition at line 178 of file checkleakautovar.cpp.
References CWE672, error, normal, and Check::reportError().
Referenced by getErrorMessages(), and ret().
|
private |
Definition at line 172 of file checkleakautovar.cpp.
References CheckMemoryLeak::deallocuseError(), Check::mErrorLogger, Check::mSettings, and Check::mTokenizer.
Referenced by checkTokenInsideExpression().
|
private |
Definition at line 198 of file checkleakautovar.cpp.
References CWE415, error, Library::isresource(), normal, and Check::reportError().
Referenced by changeAllocStatus(), and getErrorMessages().
|
private |
parse function call
Definition at line 947 of file checkleakautovar.cpp.
References VarInfo::AllocInfo::allocTok, Library::AllocFunc::arg, Token::astOperand1(), Token::astOperand2(), Token::astParent(), Scope::bodyEnd, Scope::bodyStart, changeAllocStatus(), checkTokenInsideExpression(), ValueType::container, Token::findmatch(), Token::findsimplematch(), Library::getAllocFuncInfo(), Library::getDeallocFuncInfo(), Library::getFunctionName(), Library::getReallocFuncInfo(), Library::AllocFunc::groupId, Token::hasKnownIntValue(), Token::isCast(), Token::isCpp(), Token::isKeyword(), isLambdaCaptureList(), Library::isLeakIgnore(), Library::isSmartPointer(), leakIfAllocated(), Settings::library, Token::link(), Token::linkAt(), Token::Match(), Check::mSettings, NEW, NEW_ARRAY, Token::next(), Token::nextArgument(), ValueType::pointer, Token::simpleMatch(), VarInfo::AllocInfo::status, Library::Container::stdStringLike, Token::str(), Token::tokAt(), VarInfo::AllocInfo::type, Token::type(), Token::values(), Token::valueType(), Token::variable(), and Token::varId().
Referenced by checkScope(), and checkTokenInsideExpression().
|
inlineoverrideprivatevirtual |
get error messages
Implements Check.
Definition at line 163 of file checkleakautovar.h.
References configurationInfo(), deallocReturnError(), and doubleFreeError().
|
private |
Definition at line 156 of file checkleakautovar.cpp.
References Library::isresource(), CheckMemoryLeak::memleakError(), Check::mErrorLogger, Check::mSettings, Check::mTokenizer, and CheckMemoryLeak::resourceLeakError().
Referenced by leakIfAllocated(), and ret().
if variable is allocated then there is a leak
Definition at line 1083 of file checkleakautovar.cpp.
References configurationInfo(), leakError(), Token::str(), and Token::varId().
Referenced by checkScope(), and functionCall().
|
private |
Definition at line 165 of file checkleakautovar.cpp.
References Check::mErrorLogger, CheckMemoryLeak::mismatchAllocDealloc(), Check::mSettings, and Check::mTokenizer.
Referenced by changeAllocStatus(), and changeAllocStatusIfRealloc().
|
inlinestaticprivate |
Definition at line 170 of file checkleakautovar.h.
|
private |
return.
either "return" or end of variable scope is seen
Definition at line 1115 of file checkleakautovar.cpp.
References astIsBool(), Token::astOperand1(), Token::astOperand2(), Token::astParent(), Scope::bodyEnd, Scope::bodyStart, configurationInfo(), deallocReturnError(), getOutparamAllocation(), Tokenizer::getSymbolDatabase(), SymbolDatabase::getVariableFromVarId(), Token::isCast(), Variable::isReference(), leakError(), Token::link(), Token::Match(), Check::mSettings, Check::mTokenizer, Variable::name(), Token::next(), Settings::platform, ValueType::pointer, precedes(), Token::previous(), Variable::scope(), Token::scope(), Token::simpleMatch(), Platform::sizeof_pointer, succeeds(), Token::tokAt(), Scope::type, ValueType::typeSize(), Token::valueType(), and Token::varId().
Referenced by checkScope().
|
inlineoverrideprivatevirtual |
run checks, the token list is not simplified
Implements Check.
Definition at line 118 of file checkleakautovar.h.
References check(), and Tokenizer::getSettings().