Refactorings in CheckMemoryLeak
This commit is contained in:
parent
4ba9437bd5
commit
86872f81ba
|
@ -2136,9 +2136,8 @@ static bool isNoArgument(const SymbolDatabase* symbolDatabase, unsigned int vari
|
||||||
void CheckMemoryLeakInFunction::checkReallocUsage()
|
void CheckMemoryLeakInFunction::checkReallocUsage()
|
||||||
{
|
{
|
||||||
// only check functions
|
// only check functions
|
||||||
const std::size_t functions = symbolDatabase->functionScopes.size();
|
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
|
||||||
for (std::size_t i = 0; i < functions; ++i) {
|
for (const Scope * scope : symbolDatabase->functionScopes) {
|
||||||
const Scope * scope = symbolDatabase->functionScopes[i];
|
|
||||||
|
|
||||||
// Search for the "var = realloc(var, 100" pattern within this function
|
// Search for the "var = realloc(var, 100" pattern within this function
|
||||||
for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
|
for (const Token *tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) {
|
||||||
|
@ -2200,6 +2199,8 @@ static bool isInMemberFunc(const Scope* scope)
|
||||||
|
|
||||||
void CheckMemoryLeakInFunction::check()
|
void CheckMemoryLeakInFunction::check()
|
||||||
{
|
{
|
||||||
|
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
|
||||||
|
|
||||||
// Check locking/unlocking of global resources..
|
// Check locking/unlocking of global resources..
|
||||||
for (const Scope * scope : symbolDatabase->functionScopes) {
|
for (const Scope * scope : symbolDatabase->functionScopes) {
|
||||||
if (!scope->hasInlineOrLambdaFunction())
|
if (!scope->hasInlineOrLambdaFunction())
|
||||||
|
|
|
@ -175,22 +175,17 @@ public:
|
||||||
class CPPCHECKLIB CheckMemoryLeakInFunction : private Check, public CheckMemoryLeak {
|
class CPPCHECKLIB CheckMemoryLeakInFunction : private Check, public CheckMemoryLeak {
|
||||||
public:
|
public:
|
||||||
/** @brief This constructor is used when registering this class */
|
/** @brief This constructor is used when registering this class */
|
||||||
CheckMemoryLeakInFunction() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr), symbolDatabase(nullptr) {
|
CheckMemoryLeakInFunction() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief This constructor is used when running checks */
|
/** @brief This constructor is used when running checks */
|
||||||
CheckMemoryLeakInFunction(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog)
|
CheckMemoryLeakInFunction(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
: Check(myName(), tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog, settings) {
|
: Check(myName(), tokenizer, settings, errorLogger), CheckMemoryLeak(tokenizer, errorLogger, settings) {
|
||||||
// get the symbol database
|
|
||||||
if (tokenizr)
|
|
||||||
symbolDatabase = tokenizr->getSymbolDatabase();
|
|
||||||
else
|
|
||||||
symbolDatabase = nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief run all simplified checks */
|
/** @brief run all simplified checks */
|
||||||
void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) override {
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
|
||||||
CheckMemoryLeakInFunction checkMemoryLeak(tokenizr, settings, errLog);
|
CheckMemoryLeakInFunction checkMemoryLeak(tokenizer, settings, errorLogger);
|
||||||
checkMemoryLeak.checkReallocUsage();
|
checkMemoryLeak.checkReallocUsage();
|
||||||
checkMemoryLeak.check();
|
checkMemoryLeak.check();
|
||||||
}
|
}
|
||||||
|
@ -311,8 +306,6 @@ private:
|
||||||
std::string classInfo() const override {
|
std::string classInfo() const override {
|
||||||
return "Is there any allocated memory when a function goes out of scope\n";
|
return "Is there any allocated memory when a function goes out of scope\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
const SymbolDatabase *symbolDatabase;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -326,8 +319,8 @@ public:
|
||||||
CheckMemoryLeakInClass() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {
|
CheckMemoryLeakInClass() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckMemoryLeakInClass(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog)
|
CheckMemoryLeakInClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
: Check(myName(), tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog, settings) {
|
: Check(myName(), tokenizer, settings, errorLogger), CheckMemoryLeak(tokenizer, errorLogger, settings) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) override {
|
void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) override {
|
||||||
|
@ -373,12 +366,12 @@ public:
|
||||||
CheckMemoryLeakStructMember() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {
|
CheckMemoryLeakStructMember() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckMemoryLeakStructMember(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog)
|
CheckMemoryLeakStructMember(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
: Check(myName(), tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog, settings) {
|
: Check(myName(), tokenizer, settings, errorLogger), CheckMemoryLeak(tokenizer, errorLogger, settings) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) override {
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
|
||||||
CheckMemoryLeakStructMember checkMemoryLeak(tokenizr, settings, errLog);
|
CheckMemoryLeakStructMember checkMemoryLeak(tokenizer, settings, errorLogger);
|
||||||
checkMemoryLeak.check();
|
checkMemoryLeak.check();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,12 +405,12 @@ public:
|
||||||
CheckMemoryLeakNoVar() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {
|
CheckMemoryLeakNoVar() : Check(myName()), CheckMemoryLeak(nullptr, nullptr, nullptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckMemoryLeakNoVar(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog)
|
CheckMemoryLeakNoVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||||
: Check(myName(), tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog, settings) {
|
: Check(myName(), tokenizer, settings, errorLogger), CheckMemoryLeak(tokenizer, errorLogger, settings) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) override {
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
|
||||||
CheckMemoryLeakNoVar checkMemoryLeak(tokenizr, settings, errLog);
|
CheckMemoryLeakNoVar checkMemoryLeak(tokenizer, settings, errorLogger);
|
||||||
checkMemoryLeak.check();
|
checkMemoryLeak.check();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue