From 2ddd0d263165fe5ca083d5607753ef0bb819f14a Mon Sep 17 00:00:00 2001 From: chrchr Date: Tue, 5 Mar 2024 11:00:00 +0100 Subject: [PATCH] Fix #12490 FP deallocret when returning bool --- lib/checkleakautovar.cpp | 2 +- test/testleakautovar.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 655273a9048..e85e242e79e 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -1147,7 +1147,7 @@ void CheckLeakAutoVar::ret(const Token *tok, VarInfo &varInfo, const bool isEndO tok2 = tok3; else continue; - if (Token::Match(tok2, "[});,+]")) { + if (Token::Match(tok2, "[});,+]") && !astIsBool(tok)) { used = PtrUsage::PTR; break; } diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 239d5dd75cc..411ab698e6f 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -113,6 +113,7 @@ class TestLeakAutoVar : public TestFixture { TEST_CASE(deallocuse12); TEST_CASE(deallocuse13); TEST_CASE(deallocuse14); + TEST_CASE(deallocuse15); TEST_CASE(doublefree1); TEST_CASE(doublefree2); @@ -1036,6 +1037,15 @@ class TestLeakAutoVar : public TestFixture { ASSERT_EQUALS("", errout.str()); } + void deallocuse15() { + check("bool FileExists(const char* filename) {\n" // #12490 + " FILE* f = fopen(filename, \"rb\");\n" + " if (f) fclose(f);\n" + " return f;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void doublefree1() { // #3895 check("void f(char *p) {\n" " if (x)\n"