]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: use unique_ptr for flat_map emplace in BucketTrimWatcher 52996/head
authorVedansh Bhartia <vedanshbhartia@gmail.com>
Thu, 2 Mar 2023 13:04:53 +0000 (18:34 +0530)
committerKonstantin Shalygin <k0ste@k0ste.ru>
Sat, 14 Oct 2023 08:03:28 +0000 (15:03 +0700)
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 <vedanshbhartia@gmail.com>
(cherry picked from commit 43ef4753eb338781529a7dc8360eab13d56fce85)

src/rgw/rgw_trim_bilog.cc

index 1aa24517569cfb37f015829f1fb6ddacb63bc511..a825a093c94969520796b8c7bbf337de02f393d1 100644 (file)
@@ -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<TrimCounters::Handler>(counters));
+    handlers.emplace(NotifyTrimComplete,
+        std::make_unique<TrimComplete::Handler>(counters));
   }
 
   ~BucketTrimWatcher() {