From: Vedansh Bhartia Date: Thu, 2 Mar 2023 13:04:53 +0000 (+0530) Subject: rgw: use unique_ptr for flat_map emplace in BucketTrimWatcher X-Git-Tag: v19.0.0~1569^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=43ef4753eb338781529a7dc8360eab13d56fce85;p=ceph.git rgw: use unique_ptr for flat_map emplace in BucketTrimWatcher When emplacing objects into the trim notify handler of BucketTrimWatcher, use a unique_ptr for the handler so that it is destroyed if the emplace fails. Though the destructor is already called, this behaviour cannot be relied upon. std::map does not exhibit the same behaviour, and would have leaked memory had it been used instead. Fixes: https://tracker.ceph.com/issues/57938 Signed-off-by: Vedansh Bhartia --- diff --git a/src/rgw/driver/rados/rgw_trim_bilog.cc b/src/rgw/driver/rados/rgw_trim_bilog.cc index 200d674230b54..4e34abf517883 100644 --- a/src/rgw/driver/rados/rgw_trim_bilog.cc +++ b/src/rgw/driver/rados/rgw_trim_bilog.cc @@ -253,8 +253,10 @@ class BucketTrimWatcher : public librados::WatchCtx2 { BucketTrimWatcher(rgw::sal::RadosStore* store, const rgw_raw_obj& obj, TrimCounters::Server *counters) : store(store), obj(obj) { - handlers.emplace(NotifyTrimCounters, new TrimCounters::Handler(counters)); - handlers.emplace(NotifyTrimComplete, new TrimComplete::Handler(counters)); + handlers.emplace(NotifyTrimCounters, + std::make_unique(counters)); + handlers.emplace(NotifyTrimComplete, + std::make_unique(counters)); } ~BucketTrimWatcher() {