errmsg: added "mismatching allocation and deallocation"

This commit is contained in:
Daniel Marjamäki 2009-01-10 19:30:41 +00:00
parent 327d09502a
commit 1e6b54b2c5
4 changed files with 12 additions and 2 deletions

View File

@ -305,7 +305,7 @@ void CheckMemoryLeakClass::MismatchError(const Token *Tok1, const std::list<cons
std::ostringstream errmsg;
for (std::list<const Token *>::const_iterator tok = callstack.begin(); tok != callstack.end(); ++tok)
errmsg << _tokenizer->fileLine(*tok) << " -> ";
errmsg << _tokenizer->fileLine(Tok1) << ": Mismatching allocation and deallocation: " << varname;
errmsg << ErrorMessage::mismatchAllocDealloc(_tokenizer, Tok1, varname);
_errorLogger->reportErr(errmsg.str());
}
//---------------------------------------------------------------------------

View File

@ -268,7 +268,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
// Memory leak
CheckMemoryLeakClass checkMemoryLeak(&_tokenizer, _settings, this);
if (ErrorMessage::memleak(_settings))
if (ErrorMessage::memleak(_settings) && ErrorMessage::mismatchAllocDealloc(_settings))
checkMemoryLeak.CheckMemoryLeak();
// Check that all class constructors are ok.

View File

@ -111,6 +111,15 @@ public:
return true;
}
static std::string mismatchAllocDealloc(const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
{
return msg1(tokenizer, Location) + "Mismatching allocation and deallocation: " + varname + "";
}
static bool mismatchAllocDealloc(const Settings &s)
{
return true;
}
static std::string memleak(const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
{
return msg1(tokenizer, Location) + "Memory leak: " + varname + "";

View File

@ -67,6 +67,7 @@ int main()
err.push_back(Message("virtualDestructor", 0, "Class %1 which is inherited by class %2 does not have a virtual destructor", "Base", "Derived"));
// checkmemoryleak.cpp..
err.push_back(Message("mismatchAllocDealloc", 0, "Mismatching allocation and deallocation: %1", "varname"));
err.push_back(Message("memleak", 0, "Memory leak: %1", "varname"));
err.push_back(Message("resourceLeak", 0, "Resource leak: %1", "varname"));