Fix FP (regression): Resource handle 'fd' freed twice. [doubleFree] (#5424)

This commit is contained in:
chrchr-github 2023-09-10 20:32:55 +02:00 committed by GitHub
parent 4fa1c7d5f9
commit f9b18bc9d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -281,7 +281,7 @@ static const Token * isFunctionCall(const Token * nameToken)
nameToken = nameToken->link()->next(); nameToken = nameToken->link()->next();
} }
// check for '(' // check for '('
if (nameToken && nameToken->link() && nameToken->str() == "(") { if (nameToken && nameToken->link() && !nameToken->isCast() && nameToken->str() == "(") {
// returning opening parenthesis pointer // returning opening parenthesis pointer
return nameToken; return nameToken;
} }

View File

@ -128,6 +128,7 @@ private:
TEST_CASE(doublefree12); // #10502 TEST_CASE(doublefree12); // #10502
TEST_CASE(doublefree13); // #11008 TEST_CASE(doublefree13); // #11008
TEST_CASE(doublefree14); // #9708 TEST_CASE(doublefree14); // #9708
TEST_CASE(doublefree15);
// exit // exit
TEST_CASE(exit1); TEST_CASE(exit1);
@ -1528,6 +1529,13 @@ private:
ASSERT_EQUALS("", errout.str()); 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() { void exit1() {
check("void f() {\n" check("void f() {\n"
" char *p = malloc(10);\n" " char *p = malloc(10);\n"