Skip to content

Commit

Permalink
Fix #12399 FP doubleFree for fclose in macro with __typeof__ (#5928)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jan 31, 2024
1 parent 6f6ede7 commit a1b1293
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,10 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,

const Token * closingParenthesis = tok->linkAt(1);
for (const Token *innerTok = tok->tokAt(2); innerTok && innerTok != closingParenthesis; innerTok = innerTok->next()) {
if (isUnevaluated(innerTok)) {
innerTok = innerTok->linkAt(1);
continue;
}
// TODO: replace with checkTokenInsideExpression()
const Token* const openingPar = isFunctionCall(innerTok);
if (!openingPar)
Expand Down
10 changes: 10 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,16 @@ class TestLeakAutoVar : public TestFixture {
" y = fclose(f);\n"
"}\n");
ASSERT_EQUALS("", errout.str());

check("void f() {\n"
" FILE *fp = fopen(\"abc\", \"r\");\n"
" if (({\n"
" __typeof__(fclose(fp)) r;\n"
" r = (fclose(fp));\n"
" r;\n"
" })) {}\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

void exit1() {
Expand Down

0 comments on commit a1b1293

Please sign in to comment.