From bfdf19bb221cb939009f67f07ae2c5f61fb319ef Mon Sep 17 00:00:00 2001 From: Vedansh Bhartia Date: Thu, 2 Mar 2023 18:34:53 +0530 Subject: [PATCH] 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 (cherry picked from commit 43ef4753eb338781529a7dc8360eab13d56fce85) --- src/rgw/rgw_trim_bilog.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_trim_bilog.cc b/src/rgw/rgw_trim_bilog.cc index 1aa24517569c..a825a093c949 100644 --- a/src/rgw/rgw_trim_bilog.cc +++ b/src/rgw/rgw_trim_bilog.cc @@ -250,8 +250,10 @@ class BucketTrimWatcher : public librados::WatchCtx2 { BucketTrimWatcher(rgw::sal::RGWRadosStore *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() { -- 2.47.3