From e5c507dc02c0d83be3ffcabdf260887d5c38e8dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 7 Dec 2009 19:23:33 +0100 Subject: [PATCH] Fixed #1063 (False positive: deallocated memory doesn't leak upon exception) --- lib/checkexceptionsafety.cpp | 9 +++++++++ test/testexceptionsafety.cpp | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/checkexceptionsafety.cpp b/lib/checkexceptionsafety.cpp index 70c3fc30d..d4b1c7f16 100644 --- a/lib/checkexceptionsafety.cpp +++ b/lib/checkexceptionsafety.cpp @@ -193,6 +193,15 @@ void CheckExceptionSafety::unsafeNew() if (tok->next()->varId() && localVars.find(tok->next()->varId()) != localVars.end()) varname = tok->strAt(1); } + + else if (tok->str() == "delete") + { + if (Token::simpleMatch(tok->next(), varname.c_str()) || + Token::simpleMatch(tok->next(), ("[ ] " + varname).c_str())) + { + varname = ""; + } + } } } diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index 6eddbc043..6265dc45a 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -97,6 +97,15 @@ private: " A *a2 = new (std::nothrow) A;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void a()\n" + "{\n" + " A *a1 = new A;\n" + " delete a1;\n" + " A *a2 = new A;\n" + " delete a2;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void realloc()