Fixed #3993 (Resource also reported as memory leak)

This commit is contained in:
Daniel Marjamäki 2012-09-18 16:20:09 +02:00
parent 9fd127617e
commit 9a7d09086e
2 changed files with 8 additions and 5 deletions

View File

@ -64,11 +64,14 @@ void VarInfo::possibleUsageAll(const std::string &functionName)
}
void CheckLeakAutoVar::leakError(const Token *tok, const std::string &varname)
void CheckLeakAutoVar::leakError(const Token *tok, const std::string &varname, const std::string &type)
{
const Standards standards;
CheckMemoryLeak checkmemleak(_tokenizer, _errorLogger, standards);
checkmemleak.memleakError(tok, varname);
if (type == "fopen")
checkmemleak.resourceLeakError(tok, varname);
else
checkmemleak.memleakError(tok, varname);
//reportError(tok, Severity::error, "newleak", "New memory leak: " + varname);
}
@ -523,7 +526,7 @@ void CheckLeakAutoVar::leakIfAllocated(const Token *vartok,
if (var != alloctype.end() && var->second != "dealloc") {
const std::map<unsigned int, std::string>::const_iterator use = possibleUsage.find(vartok->varId());
if (use == possibleUsage.end()) {
leakError(vartok, vartok->str());
leakError(vartok, vartok->str(), var->second);
} else {
configurationInfo(vartok, use->second);
}
@ -566,7 +569,7 @@ void CheckLeakAutoVar::ret(const Token *tok, const VarInfo &varInfo)
const std::map<unsigned int, std::string>::const_iterator use = possibleUsage.find(varid);
if (use == possibleUsage.end()) {
leakError(tok, var->name());
leakError(tok, var->name(), it->second);
} else {
configurationInfo(tok, use->second);
}

View File

@ -109,7 +109,7 @@ private:
/** if variable is allocated then there is a leak */
void leakIfAllocated(const Token *vartok, const VarInfo &varInfo);
void leakError(const Token* tok, const std::string &varname);
void leakError(const Token* tok, const std::string &varname, const std::string &type);
void mismatchError(const Token* tok, const std::string &varname);
void deallocUseError(const Token *tok, const std::string &varname);
void deallocReturnError(const Token *tok, const std::string &varname);