From b11d06a8e4c248e7efd7360950e8f2629b125502 Mon Sep 17 00:00:00 2001 From: lumir-sliva Date: Sun, 29 Mar 2026 00:56:49 +0100 Subject: [PATCH] Remove unnecessary null pointer checks before delete/free MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit delete on a null pointer is guaranteed to be a no-op by the C++ standard, and free(NULL) is a no-op per C11 ยง7.22.3.3. The redundant guards add visual noise without providing any safety benefit. Github-Issue:#53 --- auth_plugin/ProtoUtils.cc | 9 ++------- fst/http/s3/S3Handler.cc | 6 ++---- fst/xrdcl_plugins/RainFile.cc | 9 ++------- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/auth_plugin/ProtoUtils.cc b/auth_plugin/ProtoUtils.cc index dfc6dea7d2..904f2d3744 100644 --- a/auth_plugin/ProtoUtils.cc +++ b/auth_plugin/ProtoUtils.cc @@ -255,13 +255,8 @@ utils::GetXrdSfsPrep(const eos::auth::XrdSfsPrepProto& proto_obj) //------------------------------------------------------------------------------ void utils::DeleteXrdSfsPrep(XrdSfsPrep*& obj) { - if (obj->reqid) { - free(obj->reqid); - } - - if (obj->notify != nullptr) { - free(obj->notify); - } + free(obj->reqid); + free(obj->notify); XrdOucTList* currentPath = obj->paths; diff --git a/fst/http/s3/S3Handler.cc b/fst/http/s3/S3Handler.cc index 1c252c82cd..68f622a54f 100644 --- a/fst/http/s3/S3Handler.cc +++ b/fst/http/s3/S3Handler.cc @@ -132,10 +132,8 @@ S3Handler::HandleRequest(eos::common::HttpRequest* request) if (!mHttpResponse || request->GetBodySize() == 0) { // clean-up left-over objects on error or end-of-put - if (mFile) { - delete mFile; - mFile = 0; - } + delete mFile; + mFile = 0; } } } diff --git a/fst/xrdcl_plugins/RainFile.cc b/fst/xrdcl_plugins/RainFile.cc index 9ad15ed8ef..b70422eafb 100644 --- a/fst/xrdcl_plugins/RainFile.cc +++ b/fst/xrdcl_plugins/RainFile.cc @@ -52,13 +52,8 @@ RainFile::~RainFile() { eos_debug("calling destructor"); - if (pFile) { - delete pFile; - } - - if (pRainFile) { - delete pRainFile; - } + delete pFile; + delete pRainFile; }