From 27a372d3ab9bb656d6d2e127c16657baa1eb9500 Mon Sep 17 00:00:00 2001 From: Zack Winter Date: Tue, 15 Aug 2023 18:24:18 +0000 Subject: [PATCH] SERVER-79410 Enable bugprone-unused-return-value clang lint warning --- .clang-tidy.in | 2 +- src/mongo/crypto/jws_validator_openssl.cpp | 7 ++++--- src/mongo/db/cursor_manager.cpp | 4 ++-- src/mongo/transport/service_executor_utils.cpp | 4 +++- src/mongo/util/net/ssl_manager_openssl.cpp | 7 ++++--- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.clang-tidy.in b/.clang-tidy.in index 6053e4440b5..16feacba103 100644 --- a/.clang-tidy.in +++ b/.clang-tidy.in @@ -25,6 +25,7 @@ Checks: '-*, bugprone-swapped-arguments, bugprone-terminating-continue, bugprone-undelegated-constructor, + bugprone-unused-return-value, hicpp-static-assert, hicpp-undelegated-constructor, misc-static-assert, @@ -75,7 +76,6 @@ Checks: '-*, -bugprone-suspicious-missing-comma, -bugprone-suspicious-semicolon, -bugprone-undefined-memory-manipulation, - -bugprone-unused-return-value, -cert-err34-c, -cert-err52-cpp, -cert-err60-cpp, diff --git a/src/mongo/crypto/jws_validator_openssl.cpp b/src/mongo/crypto/jws_validator_openssl.cpp index 0d96f54e27b..de5c148134b 100644 --- a/src/mongo/crypto/jws_validator_openssl.cpp +++ b/src/mongo/crypto/jws_validator_openssl.cpp @@ -120,13 +120,14 @@ public: uassertOpenSSL("Failed creating RSAKey", rsa.get() != nullptr); uassertOpenSSL("RSA key setup failed", RSA_set0_key(rsa.get(), n.get(), e.get(), nullptr) == 1); - n.release(); // Now owned by rsa - e.release(); // Now owned by rsa + (void)n.release(); // Now owned by rsa, cast to void to explicitly ignore the return value. + (void)e.release(); // Now owned by rsa, cast to void to explicitly ignore the return value. uassertOpenSSL("Failed creating EVP_PKey", _key.get() != nullptr); uassertOpenSSL("EVP_PKEY assignment failed", EVP_PKEY_assign_RSA(_key.get(), rsa.get()) == 1); - rsa.release(); // Now owned by _key + (void)rsa + .release(); // Now owned by _key, cast to void to explicitly ignore the return value. } Status validate(StringData algorithm, StringData payload, StringData signature) const final { diff --git a/src/mongo/db/cursor_manager.cpp b/src/mongo/db/cursor_manager.cpp index cc3da7f8e41..90b222ef4c9 100644 --- a/src/mongo/db/cursor_manager.cpp +++ b/src/mongo/db/cursor_manager.cpp @@ -283,8 +283,8 @@ void CursorManager::unpin(OperationContext* opCtx, } // The cursor will stay around in '_cursorMap', so release the unique pointer to avoid deleting - // it. - cursor.release(); + // it. Cast to void to explicitly ignore the return value. + (void)cursor.release(); } void CursorManager::appendActiveSessions(LogicalSessionIdSet* lsids) const { diff --git a/src/mongo/transport/service_executor_utils.cpp b/src/mongo/transport/service_executor_utils.cpp index db14dfa55eb..003f0b69b8e 100644 --- a/src/mongo/transport/service_executor_utils.cpp +++ b/src/mongo/transport/service_executor_utils.cpp @@ -148,7 +148,9 @@ Status launchServiceWorkerThread(unique_function task) { "error"_attr = errorMessage(ec)); } - ctx.release(); + // The spawned thread takes over ownership, cast to void to explicitly ignore the return + // value. + (void)ctx.release(); #endif } catch (const std::exception& e) { diff --git a/src/mongo/util/net/ssl_manager_openssl.cpp b/src/mongo/util/net/ssl_manager_openssl.cpp index aca97625497..82232a9a080 100644 --- a/src/mongo/util/net/ssl_manager_openssl.cpp +++ b/src/mongo/util/net/ssl_manager_openssl.cpp @@ -1700,9 +1700,10 @@ UniqueDHParams makeDefaultDHParameters() { return nullptr; } - // DH takes over memory management responsibilities after successfully setting these - p.release(); - g.release(); + // DH takes over memory management responsibilities after successfully setting these. + // Cast to void to explicitly ignore the return value. + (void)p.release(); + (void)g.release(); return dhparams; }