Support throw in checkleakautovar.cpp
This commit is contained in:
parent
331a6b66be
commit
bdae9064ea
|
@ -388,8 +388,17 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
||||||
}
|
}
|
||||||
|
|
||||||
// throw
|
// throw
|
||||||
// TODO: if the execution leave the function then treat it as return
|
|
||||||
else if (tok->str() == "throw") {
|
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();
|
varInfo->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -661,7 +661,7 @@ private:
|
||||||
" char *p = malloc(10);\n"
|
" char *p = malloc(10);\n"
|
||||||
" throw 123;\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"
|
check("void f() {\n"
|
||||||
" char *p;\n"
|
" char *p;\n"
|
||||||
|
|
Loading…
Reference in New Issue