Support throw in checkleakautovar.cpp

This commit is contained in:
PKEuS 2015-01-22 11:12:26 +01:00
parent 331a6b66be
commit bdae9064ea
2 changed files with 11 additions and 2 deletions

View File

@ -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();
}
}

View File

@ -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"