diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 3bf761e84..394c98397 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -168,14 +168,6 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, if (tok->str() == "(" && tok->previous()->isName()) { functionCall(tok->previous(), varInfo, NOALLOC); tok = tok->link(); - - if (Token::simpleMatch(tok,") ; }")) { - bool unknown = false; - const bool noreturn = _tokenizer->IsScopeNoReturn(tok->tokAt(2), &unknown); - if (noreturn) - varInfo->clear(); - } - continue; } @@ -361,15 +353,12 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, if (dealloc == NOALLOC && Token::simpleMatch(tok, ") ; }")) { const std::string &functionName(tok->link()->previous()->str()); bool unknown = false; - if (_settings->library.leakignore.find(functionName) == _settings->library.leakignore.end() && - _settings->library.use.find(functionName) == _settings->library.use.end() && - _tokenizer->IsScopeNoReturn(tok->tokAt(2), &unknown)) { - if (unknown) { - //const std::string &functionName(tok->link()->previous()->str()); - varInfo->possibleUsageAll(functionName); - } else { + if (_tokenizer->IsScopeNoReturn(tok->tokAt(2), &unknown)) { + if (!unknown) varInfo->clear(); - } + else if (_settings->library.leakignore.find(functionName) == _settings->library.leakignore.end() && + _settings->library.use.find(functionName) == _settings->library.use.end()) + varInfo->possibleUsageAll(functionName); } } diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 9d993a5cb..72f70b7f0 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -350,12 +350,12 @@ private: } void doublefree4() { // #5451 - exit - check("void foo(char *p) {\n" - " if (x) {\n" - " free(p)\n" - " exit(1);\n" - " }\n" - " free(p);\n" + check("void f(char *p) {\n" + " if (x) {\n" + " free(p);\n" + " exit(1);\n" + " }\n" + " free(p);\n" "}"); ASSERT_EQUALS("", errout.str()); }