parent
9ec8886898
commit
cb0b057595
|
@ -316,7 +316,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
|||
|
||||
|
||||
// look for end of statement
|
||||
if (!Token::Match(tok, "[;{}]") || Token::Match(tok->next(), "[;{}]"))
|
||||
if (!Token::Match(tok, "[;{},]") || Token::Match(tok->next(), "[;{},]"))
|
||||
continue;
|
||||
|
||||
tok = tok->next();
|
||||
|
|
|
@ -94,6 +94,7 @@ private:
|
|||
TEST_CASE(doublefree7);
|
||||
TEST_CASE(doublefree8);
|
||||
TEST_CASE(doublefree9);
|
||||
TEST_CASE(doublefree10); // #8706
|
||||
|
||||
// exit
|
||||
TEST_CASE(exit1);
|
||||
|
@ -1136,6 +1137,32 @@ private:
|
|||
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() {
|
||||
check("void f() {\n"
|
||||
" char *p = malloc(10);\n"
|
||||
|
|
Loading…
Reference in New Issue