From 8f827aa65f36a5d6bbace8809fcfed2ca9ffea49 Mon Sep 17 00:00:00 2001 From: Zachary Blair Date: Sat, 4 Feb 2012 11:24:40 -0800 Subject: [PATCH] FIxed #3581 (double free false positive when exception rethrown) --- lib/checkother.cpp | 2 +- test/testother.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 76bacf23b..05c4e974e 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2533,7 +2533,7 @@ void CheckOther::checkDoubleFree() // Any control statements in-between delete, free() or closedir() statements // makes it unclear whether any subsequent statements would be redundant. - if (Token::Match(tok, "else|break|continue|goto|return")) { + if (Token::Match(tok, "else|break|continue|goto|return|throw")) { freedVariables.clear(); closeDirVariables.clear(); } diff --git a/test/testother.cpp b/test/testother.cpp index efddc0f82..cd3a41228 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -4596,6 +4596,24 @@ private: "}" ); ASSERT_EQUALS("", errout.str()); + + check( + "void bug()" + "{" + " int* ptr = NULL;" + " try" + " {" + " ptr = new int(4);" + " }" + " catch(...)" + " {" + " delete ptr;" + " throw;" + " }" + " delete ptr;" + "}" + ); + ASSERT_EQUALS("", errout.str()); } void coutCerrMisusage() {