Skip to content

Commit

Permalink
Fix #12490 FP deallocret when returning bool (#6083)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Mar 6, 2024
1 parent df7d2ba commit 63913a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 63913a6

Please sign in to comment.