From 55581fc2e97f3a3140763dbc89693830032835cc Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 23 Jun 2023 18:21:53 +0200 Subject: [PATCH] Fix FP deallocuse (#5183) --- lib/checkleakautovar.cpp | 6 ++++-- test/testleakautovar.cpp | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 976782731..ae53485d7 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 9d61b7cd7..243693239 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -2080,6 +2080,22 @@ private: " }\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() {