From 470a9a6c71dd7b62fb02de7e8c4d7f770b982f8f Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Sun, 28 Jul 2013 10:26:46 +0200 Subject: [PATCH] Take into account break and continue statements in CheckLeakAutoVar. --- lib/checkleakautovar.cpp | 5 +++++ test/testleakautovar.cpp | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 73e891ebf..d5292306a 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -370,6 +370,11 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, else if (tok->str() == "goto") { varInfo->clear(); } + + // continue/break + else if (Token::Match(tok, "continue|break ;")) { + varInfo->clear(); + } // throw // TODO: if the execution leave the function then treat it as return diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index d2945e97a..a7dcff4b5 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -56,6 +56,7 @@ private: TEST_CASE(doublefree1); TEST_CASE(doublefree2); + TEST_CASE(doublefree3); // #4914 // exit TEST_CASE(exit1); @@ -327,6 +328,24 @@ private: "}"); ASSERT_EQUALS("", errout.str()); } + + void doublefree3() { // #4914 + check("void foo() {\n" + " bool done = false;\n" + " do {\n" + " char *bar = malloc(10)\n" + " if(condition()) {\n" + " free(bar);\n" + " continue;\n" + " }\n" + " done = true;\n" + " free(bar)\n" + " } while(!done);\n" + " return;" + "}" + ); + ASSERT_EQUALS("", errout.str()); + } void exit1() { check("void f() {\n"