diff --git a/lib/checkother.cpp b/lib/checkother.cpp index c61bc73de..a2fbc3740 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2716,8 +2716,6 @@ void CheckOther::checkDoubleFree() std::set closeDirVariables; for (const Token* tok = _tokenizer->tokens(); tok; tok = tok->next()) { - bool isUnknown = true; - // Keep track of any variables passed to "free()", "g_free()" or "closedir()", // and report an error if the same variable is passed twice. if (Token::Match(tok, "free|g_free|closedir ( %var% )")) { @@ -2751,7 +2749,7 @@ void CheckOther::checkDoubleFree() } // If this scope doesn't return, clear the set of previously freed variables - else if (tok->str() == "}" && _tokenizer->IsScopeNoReturn(tok, &isUnknown) && !isUnknown) { + else if (tok->str() == "}" && _tokenizer->IsScopeNoReturn(tok)) { freedVariables.clear(); closeDirVariables.clear(); } diff --git a/test/testother.cpp b/test/testother.cpp index 5cfce129e..7978f3352 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -6222,7 +6222,7 @@ private: " free(x);\n" "}" ); - ASSERT_EQUALS("[test.cpp:8]: (error) Memory pointed to by 'x' is freed twice.\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:8]: (error) Memory pointed to by 'x' is freed twice.\n", "", errout.str()); check( "void foo(int y)\n" @@ -6265,7 +6265,53 @@ private: " free(p);\n" "}" ); - ASSERT_EQUALS("[test.cpp:8]: (error) Memory pointed to by 'p' is freed twice.\n", errout.str()); + TODO_ASSERT_EQUALS("[test.cpp:8]: (error) Memory pointed to by 'p' is freed twice.\n", "", errout.str()); + + check( + "void MyFuction()\n" + "{\n" + " char* data = new char[100];\n" + " try\n" + " {\n" + " }\n" + " catch(err)\n" + " {\n" + " delete[] data;\n" + " MyThrow(err);\n" + " }\n" + " delete[] data;\n" + "}\n" + + "void MyThrow(err)\n" + "{\n" + " throw(err);\n" + "}\n" + ); + ASSERT_EQUALS("", errout.str()); + + check( + "void MyFuction()\n" + "{\n" + " char* data = new char[100];\n" + " try\n" + " {\n" + " }\n" + " catch(err)\n" + " {\n" + " delete[] data;\n" + " MyExit(err);\n" + " }\n" + " delete[] data;\n" + "}\n" + + "void MyExit(err)\n" + "{\n" + " exit(err);\n" + "}\n" + ); + ASSERT_EQUALS("", errout.str()); + + }