Skip to content

Commit a1b1293

Browse files
Fix #12399 FP doubleFree for fclose in macro with __typeof__ (#5928)
1 parent 6f6ede7 commit a1b1293

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

lib/checkleakautovar.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,10 @@ bool CheckLeakAutoVar::checkScope(const Token * const startToken,
468468

469469
const Token * closingParenthesis = tok->linkAt(1);
470470
for (const Token *innerTok = tok->tokAt(2); innerTok && innerTok != closingParenthesis; innerTok = innerTok->next()) {
471+
if (isUnevaluated(innerTok)) {
472+
innerTok = innerTok->linkAt(1);
473+
continue;
474+
}
471475
// TODO: replace with checkTokenInsideExpression()
472476
const Token* const openingPar = isFunctionCall(innerTok);
473477
if (!openingPar)

test/testleakautovar.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,16 @@ class TestLeakAutoVar : public TestFixture {
17011701
" y = fclose(f);\n"
17021702
"}\n");
17031703
ASSERT_EQUALS("", errout.str());
1704+
1705+
check("void f() {\n"
1706+
" FILE *fp = fopen(\"abc\", \"r\");\n"
1707+
" if (({\n"
1708+
" __typeof__(fclose(fp)) r;\n"
1709+
" r = (fclose(fp));\n"
1710+
" r;\n"
1711+
" })) {}\n"
1712+
"}\n");
1713+
ASSERT_EQUALS("", errout.str());
17041714
}
17051715

17061716
void exit1() {

0 commit comments

Comments
 (0)