From: xie xingguo Date: Mon, 3 Jul 2017 08:17:30 +0000 (+0800) Subject: mon/OSDMonitor: fix potential memory leak X-Git-Tag: v12.1.1~119^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8eaf7c048addc5d05f4cb33745e18b31d442faf4;p=ceph.git mon/OSDMonitor: fix potential memory leak Signed-off-by: xie xingguo --- diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 69dc7d43ba0c..8f5e12c04a3f 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);