* 8706

* Add test case for #8706
This commit is contained in:
Ken-Patrick 2019-08-07 08:04:10 +02:00 committed by Daniel Marjamäki
parent 9ec8886898
commit cb0b057595
2 changed files with 28 additions and 1 deletions

View File

@ -316,7 +316,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
// look for end of statement // look for end of statement
if (!Token::Match(tok, "[;{}]") || Token::Match(tok->next(), "[;{}]")) if (!Token::Match(tok, "[;{},]") || Token::Match(tok->next(), "[;{},]"))
continue; continue;
tok = tok->next(); tok = tok->next();

View File

@ -94,6 +94,7 @@ private:
TEST_CASE(doublefree7); TEST_CASE(doublefree7);
TEST_CASE(doublefree8); TEST_CASE(doublefree8);
TEST_CASE(doublefree9); TEST_CASE(doublefree9);
TEST_CASE(doublefree10); // #8706
// exit // exit
TEST_CASE(exit1); TEST_CASE(exit1);
@ -1136,6 +1137,32 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void doublefree10() {
check("void f(char* s) {\n"
" char *p = malloc(strlen(s));\n"
" if (p != NULL) {\n"
" strcat(p, s);\n"
" if (strlen(s) != 10)\n"
" free(p); p = NULL;\n"
" }\n"
" if (p != NULL)\n"
" free(p);\n"
"}\n", true);
ASSERT_EQUALS("", errout.str());
check("void f(char* s) {\n"
" char *p = malloc(strlen(s));\n"
" if (p != NULL) {\n"
" strcat(p, s);\n"
" if (strlen(s) != 10)\n"
" free(p), p = NULL;\n"
" }\n"
" if (p != NULL)\n"
" free(p);\n"
"}\n", true);
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"