Skip to content

Commit fb61706

Browse files
Fix #14171 FP leakReturnValNotUsed with freopen() (danmar#7866)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 68454d6 commit fb61706

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/checkmemoryleak.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,8 @@ void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope)
11171117
if (!(Token::simpleMatch(parent->astParent(), "?") && !parent->astParent()->astParent()))
11181118
continue;
11191119
}
1120+
if (tok->str() == "freopen")
1121+
continue;
11201122
returnValueNotUsedError(tok, tok->str());
11211123
}
11221124
}

test/testmemleak.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,6 +2701,12 @@ class TestMemleakNoVar : public TestFixture {
27012701
" delete[] &p[-1];\n"
27022702
"}\n");
27032703
ASSERT_EQUALS("", errout_str());
2704+
2705+
check("void f(FILE* fp1, FILE* fp2) {\n" // #14171
2706+
" if (freopen(NULL, \"w+b\", fp1) == NULL) {}\n"
2707+
" if (std::freopen(NULL, \"w+b\", fp2) == NULL) {}\n"
2708+
"}\n");
2709+
ASSERT_EQUALS("", errout_str());
27042710
}
27052711

27062712
void smartPointerFunctionParam() {

0 commit comments

Comments
 (0)