From: Ken Iizawa Date: Fri, 12 Feb 2021 06:58:43 +0000 (+0900) Subject: osd: fix potential memory leak X-Git-Tag: v17.1.0~2291^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=26dd006b2a546a5665f9fc8468ebe32cecc30ba2;p=ceph.git osd: fix potential memory leak Fixes: https://tracker.ceph.com/issues/48182 Signed-off-by: Ken Iizawa --- diff --git a/src/osd/objclass.cc b/src/osd/objclass.cc index 8117c228717..6cb91477cc3 100644 --- a/src/osd/objclass.cc +++ b/src/osd/objclass.cc @@ -702,8 +702,7 @@ uint64_t cls_get_pool_stripe_width(cls_method_context_t hctx) } struct GatherFinisher : public PrimaryLogPG::OpFinisher { - std::map *src_obj_buffs; - GatherFinisher(std::map *sob) : src_obj_buffs(sob) {} + std::map src_obj_buffs; int execute() override { return 0; } @@ -713,12 +712,13 @@ int cls_cxx_gather(cls_method_context_t hctx, const std::set &src_o const char *cls, const char *method, bufferlist& inbl) { PrimaryLogPG::OpContext **pctx = (PrimaryLogPG::OpContext**)hctx; - std::map *src_obj_buffs = new std::map; - for (std::set::const_iterator it = src_objs.begin(); it != src_objs.end(); ++it) { - (*src_obj_buffs)[*it] = bufferlist(); + auto [iter, inserted] = (*pctx)->op_finishers.emplace(std::make_pair((*pctx)->current_osd_subop_num, std::make_unique())); + assert(inserted); + auto &gather = *static_cast(iter->second.get()); + for (const auto &obj : src_objs) { + gather.src_obj_buffs[obj] = bufferlist(); } - (*pctx)->op_finishers[(*pctx)->current_osd_subop_num].reset(new GatherFinisher(src_obj_buffs)); - return (*pctx)->pg->start_cls_gather(*pctx, src_obj_buffs, pool, cls, method, inbl); + return (*pctx)->pg->start_cls_gather(*pctx, &gather.src_obj_buffs, pool, cls, method, inbl); } int cls_cxx_get_gathered_data(cls_method_context_t hctx, std::map *results) @@ -736,8 +736,7 @@ int cls_cxx_get_gathered_data(cls_method_context_t hctx, std::mapclear(); } else { GatherFinisher *gf = (GatherFinisher*)op_finisher; - *results = *gf->src_obj_buffs; - delete gf->src_obj_buffs; + *results = gf->src_obj_buffs; r = (*pctx)->pg->finish_cls_gather(*pctx); } return r;