From bdae9064eaf78ab3e7184df0b5b61ea056962b3e Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 22 Jan 2015 11:12:26 +0100 Subject: [PATCH] Support throw in checkleakautovar.cpp --- lib/checkleakautovar.cpp | 11 ++++++++++- test/testleakautovar.cpp | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index f35ab543d..d9209897f 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -388,8 +388,17 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, } // throw - // TODO: if the execution leave the function then treat it as return else if (tok->str() == "throw") { + bool tryFound = false; + const Scope* scope = tok->scope(); + while (scope && scope->isExecutable()) { + if (scope->type == Scope::eTry) + tryFound = true; + scope = scope->nestedIn; + } + // If the execution leaves the function then treat it as return + if (!tryFound) + ret(tok, *varInfo); varInfo->clear(); } } diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index b05f7fa5c..4060b4ebb 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -661,7 +661,7 @@ private: " char *p = malloc(10);\n" " throw 123;\n" "}"); - TODO_ASSERT_EQUALS("error", "", errout.str()); + ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p\n", errout.str()); check("void f() {\n" " char *p;\n"