Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12590 FP: (regression) resourceLeak #6235

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading