From 8eaf7c048addc5d05f4cb33745e18b31d442faf4 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Mon, 3 Jul 2017 16:17:30 +0800 Subject: [PATCH] mon/OSDMonitor: fix potential memory leak Signed-off-by: xie xingguo --- src/mon/OSDMonitor.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 69dc7d43ba0..8f5e12c04a3 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -72,6 +72,7 @@ #include "common/cmdparse.h" #include "include/str_list.h" #include "include/str_map.h" +#include "include/scope_guard.h" #include "json_spirit/json_spirit_reader.h" @@ -3883,6 +3884,12 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op) p->decode(osdmap_bl); } + auto sg = make_scope_guard([&] { + if (p != &osdmap) { + delete p; + } + }); + if (prefix == "osd dump") { stringstream ds; if (f) { @@ -3996,8 +4003,6 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op) rdata.append(ds); } - if (p != &osdmap) - delete p; } else if (prefix == "osd df") { string method; cmd_getval(g_ceph_context, cmdmap, "output_method", method); -- 2.39.5