Fixed #4231 (False positive: (error) Returning/dereferencing 'ptr' after it is deallocated / released (ignoring goto))

This commit is contained in:
Daniel Marjamäki 2012-10-08 17:23:47 +02:00
parent 61183e7896
commit f74c30e116
2 changed files with 19 additions and 0 deletions

View File

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

View File

@ -61,6 +61,7 @@ private:
// goto
TEST_CASE(goto1);
TEST_CASE(goto2);
// if/else
TEST_CASE(ifelse1);
@ -324,6 +325,19 @@ private:
ASSERT_EQUALS("", errout.str());
}
void goto2() { // #4231
check("static char * f() {\n"
"x:\n"
" char *p = malloc(100);\n"
" if (err) {\n"
" free(p);\n"
" goto x;\n"
" }\n"
" return p;\n" // no error since there is a goto
"}");
ASSERT_EQUALS("", errout.str());
}
void ifelse1() {
check("int f() {\n"
" char *p = NULL;\n"