diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index c1012de11..3bf761e84 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -168,6 +168,14 @@ 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; } diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 7d4d03b5b..9d993a5cb 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -57,6 +57,7 @@ private: TEST_CASE(doublefree1); TEST_CASE(doublefree2); TEST_CASE(doublefree3); // #4914 + TEST_CASE(doublefree4); // #5451 - FP when exit is called // exit TEST_CASE(exit1); @@ -348,6 +349,17 @@ private: ASSERT_EQUALS("", errout.str()); } + void doublefree4() { // #5451 - exit + check("void foo(char *p) {\n" + " if (x) {\n" + " free(p)\n" + " exit(1);\n" + " }\n" + " free(p);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void exit1() { check("void f() {\n" " char *p = malloc(10);\n" diff --git a/tools/dmake.cpp b/tools/dmake.cpp index b07ba3844..2828160a8 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -160,7 +160,7 @@ int main(int argc, char **argv) std::vector testfiles; getCppFiles(testfiles, "test/"); - + std::vector toolsfiles; getCppFiles(toolsfiles, "tools/");