diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 97678273155..ae53485d7c1 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -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(); diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 9d61b7cd7d1..24369323966 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -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() {