Skip to content

Commit

Permalink
Fix FP deallocuse (#5183)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jun 23, 2023
1 parent 04476bc commit 55581fc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,10 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
}
closingParenthesis = closingParenthesis->linkAt(1);
if (Token::simpleMatch(closingParenthesis, "} else {")) {
if (!checkScope(closingParenthesis->tokAt(2), varInfo2, notzero, recursiveCount))
continue;
if (!checkScope(closingParenthesis->tokAt(2), varInfo2, notzero, recursiveCount)) {
varInfo.clear();
return false;
}
tok = closingParenthesis->linkAt(2)->previous();
} else {
tok = closingParenthesis->previous();
Expand Down
16 changes: 16 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,22 @@ class TestLeakAutoVar : public TestFixture {
" }\n"
"}\n");
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() {
Expand Down

0 comments on commit 55581fc

Please sign in to comment.