From f7e2ca021109f4204bab416214830e10e6c2e391 Mon Sep 17 00:00:00 2001 From: Oshrey Avraham Date: Sun, 13 Oct 2024 19:27:43 +0300 Subject: [PATCH] rgw/dbstore: Cleanup - use unique_ptr instead of new/delete in DBZone This commit refactors the 'DBZone' class to utilize 'std::unique_ptr' instead of raw pointers and manual memory management with 'new' and 'delete'. Fixes: https://tracker.ceph.com/issues/57501 Signed-off-by: Oshrey Avraham --- src/rgw/rgw_sal_dbstore.h | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/rgw/rgw_sal_dbstore.h b/src/rgw/rgw_sal_dbstore.h index 107ba735a63..b54249df031 100644 --- a/src/rgw/rgw_sal_dbstore.h +++ b/src/rgw/rgw_sal_dbstore.h @@ -268,22 +268,22 @@ protected: class DBZone : public StoreZone { protected: DBStore* store; - RGWRealm *realm{nullptr}; - DBZoneGroup *zonegroup{nullptr}; - RGWZone *zone_public_config{nullptr}; /* external zone params, e.g., entrypoints, log flags, etc. */ - RGWZoneParams *zone_params{nullptr}; /* internal zone params, e.g., rados pools */ - RGWPeriod *current_period{nullptr}; + std::unique_ptr realm; + std::unique_ptr zonegroup; + std::unique_ptr zone_public_config; /* external zone params, e.g., entrypoints, log flags, etc. */ + std::unique_ptr zone_params; /* internal zone params, e.g., rados pools */ + std::unique_ptr current_period; public: DBZone(DBStore* _store) : store(_store) { - realm = new RGWRealm(); + realm = std::make_unique(); std::unique_ptr rzg = std::make_unique("default", "default"); rzg->api_name = "default"; rzg->is_master = true; - zonegroup = new DBZoneGroup(store, std::move(rzg)); - zone_public_config = new RGWZone(); - zone_params = new RGWZoneParams(); - current_period = new RGWPeriod(); + zonegroup = std::make_unique(store, std::move(rzg)); + zone_public_config = std::make_unique(); + zone_params = std::make_unique(); + current_period = std::make_unique(); // XXX: only default and STANDARD supported for now RGWZonePlacementInfo info; @@ -292,13 +292,7 @@ protected: info.storage_classes = sc; zone_params->placement_pools["default"] = info; } - ~DBZone() { - delete realm; - delete zonegroup; - delete zone_public_config; - delete zone_params; - delete current_period; - } + ~DBZone() = default; virtual std::unique_ptr clone() override { return std::make_unique(store); -- 2.39.5