Take into account break and continue statements in CheckLeakAutoVar.

This commit is contained in:
Simon Martin 2013-07-28 10:26:46 +02:00
parent be11c47b82
commit 470a9a6c71
2 changed files with 24 additions and 0 deletions

View File

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

View File

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