Skip to content

Commit

Permalink
Fix FP (regression): Resource handle 'fd' freed twice. [doubleFree] (d…
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Sep 10, 2023
1 parent 4fa1c7d commit f9b18bc
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 @@ -281,7 +281,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

0 comments on commit f9b18bc

Please sign in to comment.