diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 04a94ea31a5..787df56d1fe 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1117,6 +1117,8 @@ void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope) if (!(Token::simpleMatch(parent->astParent(), "?") && !parent->astParent()->astParent())) continue; } + if (tok->str() == "freopen") + continue; returnValueNotUsedError(tok, tok->str()); } } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index a6a7abb51c0..d93323c29ef 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2701,6 +2701,12 @@ class TestMemleakNoVar : public TestFixture { " delete[] &p[-1];\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("void f(FILE* fp1, FILE* fp2) {\n" // #14171 + " if (freopen(NULL, \"w+b\", fp1) == NULL) {}\n" + " if (std::freopen(NULL, \"w+b\", fp2) == NULL) {}\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void smartPointerFunctionParam() {