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

@ -371,6 +371,11 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
varInfo->clear(); varInfo->clear();
} }
// continue/break
else if (Token::Match(tok, "continue|break ;")) {
varInfo->clear();
}
// throw // throw
// TODO: if the execution leave the function then treat it as return // TODO: if the execution leave the function then treat it as return
else if (tok->str() == "throw") { else if (tok->str() == "throw") {

View File

@ -56,6 +56,7 @@ private:
TEST_CASE(doublefree1); TEST_CASE(doublefree1);
TEST_CASE(doublefree2); TEST_CASE(doublefree2);
TEST_CASE(doublefree3); // #4914
// exit // exit
TEST_CASE(exit1); TEST_CASE(exit1);
@ -328,6 +329,24 @@ private:
ASSERT_EQUALS("", errout.str()); 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() { void exit1() {
check("void f() {\n" check("void f() {\n"
" char *p = malloc(10);\n" " char *p = malloc(10);\n"