Skip to content

Commit

Permalink
Fix #12590 FP: (regression) resourceLeak (#6235)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Apr 5, 2024
1 parent 2361df9 commit 9deefe4
Show file tree
Hide file tree
Showing 2 changed files with 9 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 @@ -1155,7 +1155,7 @@ void CheckLeakAutoVar::ret(const Token *tok, VarInfo &varInfo, const bool isEndO
tok2 = tok3;
else
continue;
if (Token::Match(tok2, "[});,+]") && !astIsBool(tok)) {
if (Token::Match(tok2, "[});,+]") && (!astIsBool(tok) || tok2->str() != ";")) {
used = PtrUsage::PTR;
break;
}
Expand Down
8 changes: 8 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,14 @@ class TestLeakAutoVar : public TestFixture {
" return f;\n"
"}\n");
ASSERT_EQUALS("", errout_str());

check("bool f() {\n" // #12590
" FILE* fd = fopen(\"/foo/bar\", \"w\");\n"
" if (fd == nullptr)\n"
" return false;\n"
" return fclose(fd) == 0;\n"
"}\n", /*cpp*/ true);
ASSERT_EQUALS("", errout_str());
}

void doublefree1() { // #3895
Expand Down

0 comments on commit 9deefe4

Please sign in to comment.