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 FP (regression): Resource handle 'fd' freed twice. [doubleFree] #5424

Merged
merged 1 commit into from
Sep 10, 2023
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 @@ -280,7 +280,7 @@ static const Token * isFunctionCall(const Token * nameToken)
nameToken = nameToken->link()->next();
}
// check for '('
if (nameToken && nameToken->link() && nameToken->str() == "(") {
if (nameToken && nameToken->link() && !nameToken->isCast() && nameToken->str() == "(") {
// returning opening parenthesis pointer
return nameToken;
}
Expand Down
8 changes: 8 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class TestLeakAutoVar : public TestFixture {
TEST_CASE(doublefree12); // #10502
TEST_CASE(doublefree13); // #11008
TEST_CASE(doublefree14); // #9708
TEST_CASE(doublefree15);

// exit
TEST_CASE(exit1);
Expand Down Expand Up @@ -1528,6 +1529,13 @@ class TestLeakAutoVar : public TestFixture {
ASSERT_EQUALS("", errout.str());
}

void doublefree15() { // #11966
check("void f(FILE* fp) {\n"
" static_cast<void>(fclose(fp));\n"
"}", true);
ASSERT_EQUALS("", errout.str());
}

void exit1() {
check("void f() {\n"
" char *p = malloc(10);\n"
Expand Down
Loading