Skip to content

Commit 55581fc

Browse files
Fix FP deallocuse (#5183)
1 parent 04476bc commit 55581fc

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

lib/checkleakautovar.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,10 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
545545
}
546546
closingParenthesis = closingParenthesis->linkAt(1);
547547
if (Token::simpleMatch(closingParenthesis, "} else {")) {
548-
if (!checkScope(closingParenthesis->tokAt(2), varInfo2, notzero, recursiveCount))
549-
continue;
548+
if (!checkScope(closingParenthesis->tokAt(2), varInfo2, notzero, recursiveCount)) {
549+
varInfo.clear();
550+
return false;
551+
}
550552
tok = closingParenthesis->linkAt(2)->previous();
551553
} else {
552554
tok = closingParenthesis->previous();

test/testleakautovar.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,6 +2080,22 @@ class TestLeakAutoVar : public TestFixture {
20802080
" }\n"
20812081
"}\n");
20822082
ASSERT_EQUALS("", errout.str());
2083+
2084+
check("void f(node **p) {\n"
2085+
" node* n = *p;\n"
2086+
" if (n->left == NULL) {\n"
2087+
" *p = n->right;\n"
2088+
" free(n);\n"
2089+
" }\n"
2090+
" else if (n->right == NULL) {\n"
2091+
" *p = n->left;\n"
2092+
" free(n);\n"
2093+
" }\n"
2094+
" else {\n"
2095+
" for (int i = 0; i < 4; ++i) {}\n"
2096+
" }\n"
2097+
"}\n");
2098+
ASSERT_EQUALS("", errout.str());
20832099
}
20842100

20852101
void mismatchAllocDealloc() {

0 commit comments

Comments
 (0)