Fix issue detected by Coverity, dereference tok3 and then check if its null.
This commit is contained in:
parent
e977cea04c
commit
f7514fcd2c
|
@ -2650,15 +2650,19 @@ void CheckMemoryLeakNoVar::check()
|
||||||
// parse the executable scope until tok is reached...
|
// parse the executable scope until tok is reached...
|
||||||
for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
|
for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) {
|
||||||
// allocating memory in parameter for function call..
|
// allocating memory in parameter for function call..
|
||||||
if (Token::Match(tok, "[(,] %name% (") && Token::Match(tok->linkAt(2), ") [,)]")) {
|
if (!(Token::Match(tok, "[(,] %name% (") && Token::Match(tok->linkAt(2), ") [,)]")))
|
||||||
if (getAllocationType(tok->next(), 0) != No) {
|
continue;
|
||||||
|
if (getAllocationType(tok->next(), 0) == No)
|
||||||
|
continue;
|
||||||
// locate outer function call..
|
// locate outer function call..
|
||||||
const Token* tok3 = tok;
|
const Token* tok3 = tok;
|
||||||
while (tok3->astParent() && tok3->str() == ",")
|
while (tok3 && tok3->astParent() && tok3->str() == ",")
|
||||||
tok3 = tok3->astParent();
|
tok3 = tok3->astParent();
|
||||||
if (tok3 && tok3->str() == "(") {
|
if (!tok3 || tok3->str() != "(")
|
||||||
|
continue;
|
||||||
// Is it a function call..
|
// Is it a function call..
|
||||||
if (!Token::Match(tok3->tokAt(-2), "= %name% (")) {
|
if (!Token::Match(tok3->tokAt(-2), "!!= %name% ("))
|
||||||
|
continue;
|
||||||
const std::string& functionName = tok3->strAt(-1);
|
const std::string& functionName = tok3->strAt(-1);
|
||||||
if ((tokenizer->isCPP() && functionName == "delete") ||
|
if ((tokenizer->isCPP() && functionName == "delete") ||
|
||||||
functionName == "free" ||
|
functionName == "free" ||
|
||||||
|
@ -2672,10 +2676,6 @@ void CheckMemoryLeakNoVar::check()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
// Checks if a call to an allocation function like malloc() is made and its return value is not assigned.
|
// Checks if a call to an allocation function like malloc() is made and its return value is not assigned.
|
||||||
|
|
Loading…
Reference in New Issue