Fix issue detected by Coverity, dereference tok3 and then check if its null.

This commit is contained in:
Daniel Marjamäki 2017-08-02 08:38:36 +02:00
parent e977cea04c
commit f7514fcd2c
1 changed files with 22 additions and 22 deletions

View File

@ -2650,28 +2650,28 @@ 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;
// locate outer function call.. if (getAllocationType(tok->next(), 0) == No)
const Token* tok3 = tok; continue;
while (tok3->astParent() && tok3->str() == ",") // locate outer function call..
tok3 = tok3->astParent(); const Token* tok3 = tok;
if (tok3 && tok3->str() == "(") { while (tok3 && tok3->astParent() && tok3->str() == ",")
// Is it a function call.. tok3 = tok3->astParent();
if (!Token::Match(tok3->tokAt(-2), "= %name% (")) { if (!tok3 || tok3->str() != "(")
const std::string& functionName = tok3->strAt(-1); continue;
if ((tokenizer->isCPP() && functionName == "delete") || // Is it a function call..
functionName == "free" || if (!Token::Match(tok3->tokAt(-2), "!!= %name% ("))
functionName == "fclose" || continue;
functionName == "realloc") const std::string& functionName = tok3->strAt(-1);
break; if ((tokenizer->isCPP() && functionName == "delete") ||
if (CheckMemoryLeakInFunction::test_white_list(functionName, _settings, tokenizer->isCPP())) { functionName == "free" ||
functionCallLeak(tok, tok->strAt(1), functionName); functionName == "fclose" ||
break; functionName == "realloc")
} break;
} if (CheckMemoryLeakInFunction::test_white_list(functionName, _settings, tokenizer->isCPP())) {
} functionCallLeak(tok, tok->strAt(1), functionName);
} break;
} }
} }
} }