]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/OSDMonitor: fix potential memory leak
authorxie xingguo <xie.xingguo@zte.com.cn>
Mon, 3 Jul 2017 08:17:30 +0000 (16:17 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Thu, 6 Jul 2017 02:18:31 +0000 (10:18 +0800)
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/mon/OSDMonitor.cc

index 69dc7d43ba0cf35d444a859d1620bd6479d57918..8f5e12c04a3fd4b73e6bb243a956f84266bad733 100644 (file)
@@ -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);