From 0cf2c2b3273f3232a1c9264374bdec4e66317d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 1 Jun 2012 19:08:50 +0200 Subject: [PATCH] Fixed #3862 (Double deallocation does not take throws into account) --- lib/checkleakautovar.cpp | 2 +- test/testleakautovar.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 779555de2..afee74b4f 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -393,7 +393,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, } // return - else if (tok->str() == "return") { + else if (tok->str() == "return" || tok->str() == "throw") { ret(tok, *varInfo); varInfo->clear(); } diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index c441f5f19..1fb3170fe 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -77,6 +77,7 @@ private: TEST_CASE(return1); TEST_CASE(return2); TEST_CASE(return3); + TEST_CASE(return4); // General tests: variable type, allocation type, etc TEST_CASE(test1); @@ -381,6 +382,17 @@ private: ASSERT_EQUALS("", errout.str()); } + void return4() { + check("void f(char *p, int x) {\n" + " if (x==12) {n" + " free(p);\n" + " throw 1;\n" + " }\n" + " free(p);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void test1() { // 3809 check("void f(double*&p) {\n" " p = malloc(0x100);\n"