Fix FP deallocuse (#5183)

This commit is contained in:
chrchr-github 2023-06-23 18:21:53 +02:00 committed by GitHub
parent 04476bc102
commit 55581fc2e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -545,8 +545,10 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
} }
closingParenthesis = closingParenthesis->linkAt(1); closingParenthesis = closingParenthesis->linkAt(1);
if (Token::simpleMatch(closingParenthesis, "} else {")) { if (Token::simpleMatch(closingParenthesis, "} else {")) {
if (!checkScope(closingParenthesis->tokAt(2), varInfo2, notzero, recursiveCount)) if (!checkScope(closingParenthesis->tokAt(2), varInfo2, notzero, recursiveCount)) {
continue; varInfo.clear();
return false;
}
tok = closingParenthesis->linkAt(2)->previous(); tok = closingParenthesis->linkAt(2)->previous();
} else { } else {
tok = closingParenthesis->previous(); tok = closingParenthesis->previous();

View File

@ -2080,6 +2080,22 @@ private:
" }\n" " }\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("void f(node **p) {\n"
" node* n = *p;\n"
" if (n->left == NULL) {\n"
" *p = n->right;\n"
" free(n);\n"
" }\n"
" else if (n->right == NULL) {\n"
" *p = n->left;\n"
" free(n);\n"
" }\n"
" else {\n"
" for (int i = 0; i < 4; ++i) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void mismatchAllocDealloc() { void mismatchAllocDealloc() {