From 42b85088c53572e34a824775bcacb8a792d6da8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 4 May 2014 13:11:21 +0200 Subject: [PATCH] Double free: Improved handling of noreturn functions. Partial revert of previous fix. --- lib/checkleakautovar.cpp | 21 +++++---------------- test/testleakautovar.cpp | 12 ++++++------ 2 files changed, 11 insertions(+), 22 deletions(-) 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()); }