]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/admin_socket: Use unique_ptr instead of new/delete 20274/head
authorAdam C. Emerson <aemerson@redhat.com>
Tue, 30 Jan 2018 21:44:00 +0000 (16:44 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Fri, 16 Feb 2018 19:31:35 +0000 (14:31 -0500)
Mostly for the default hooks, plus one Formatter.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/common/admin_socket.cc
src/common/admin_socket.h

index 83bb68b5417414d2bc12d843c7335479fc0dbc1e..4e014ae2d868a5dbc1bdab68aa4b11106b8435d9 100644 (file)
@@ -517,7 +517,8 @@ public:
   bool call(std::string_view command, const cmdmap_t& cmdmap,
            std::string_view format,
            bufferlist& out) override {
-    auto f = Formatter::create(format, "json-pretty"sv, "json-pretty"sv);
+    std::unique_ptr<Formatter> f(Formatter::create(format, "json-pretty"sv,
+                                                  "json-pretty"sv));
     f->open_object_section("help");
     for (const auto& [command, info] : m_as->hooks) {
       if (info.help.length())
@@ -527,7 +528,6 @@ public:
     ostringstream ss;
     f->flush(ss);
     out.append(ss.str());
-    delete f;
     return true;
   }
 };
@@ -589,15 +589,17 @@ bool AdminSocket::init(const std::string& path)
   m_shutdown_wr_fd = pipe_wr;
   m_path = path;
 
-  m_version_hook = new VersionHook;
-  register_command("0", "0", m_version_hook, "");
-  register_command("version", "version", m_version_hook, "get ceph version");
-  register_command("git_version", "git_version", m_version_hook, "get git sha1");
-  m_help_hook = new HelpHook(this);
-  register_command("help", "help", m_help_hook, "list available commands");
-  m_getdescs_hook = new GetdescsHook(this);
+  version_hook = std::make_unique<VersionHook>();
+  register_command("0", "0", version_hook.get(), "");
+  register_command("version", "version", version_hook.get(), "get ceph version");
+  register_command("git_version", "git_version", version_hook.get(),
+                  "get git sha1");
+  help_hook = std::make_unique<HelpHook>(this);
+  register_command("help", "help", help_hook.get(),
+                  "list available commands");
+  getdescs_hook = std::make_unique<GetdescsHook>(this);
   register_command("get_command_descriptions", "get_command_descriptions",
-                  m_getdescs_hook, "list available commands");
+                  getdescs_hook.get(), "list available commands");
 
   th = make_named_thread("admin_socket", &AdminSocket::entry, this);
   add_cleanup_file(m_path.c_str());
@@ -624,13 +626,13 @@ void AdminSocket::shutdown()
   unregister_command("version");
   unregister_command("git_version");
   unregister_command("0");
-  delete m_version_hook;
+  version_hook.reset();
 
   unregister_command("help");
-  delete m_help_hook;
+  help_hook.reset();
 
   unregister_command("get_command_descriptions");
-  delete m_getdescs_hook;
+  getdescs_hook.reset();
 
   remove_cleanup_file(m_path);
   m_path.clear();
index 1296820e22b0de4b40aa1142a0c9cb9ded20b382..2178d711cfeed6353d4711e8ff916781c5e908fb 100644 (file)
@@ -1,4 +1,4 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 // vim: ts=8 sw=2 smarttab
 /*
  * Ceph - scalable distributed file system
@@ -7,9 +7,9 @@
  *
  * This is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software 
+ * License version 2.1, as published by the Free Software
  * Foundation.  See file COPYING.
- * 
+ *
  */
 
 #ifndef CEPH_COMMON_ADMIN_SOCKET_H
@@ -114,8 +114,9 @@ private:
   bool in_hook = false;
   std::condition_variable in_hook_cond;
   std::mutex lock;  // protects `hooks`
-  AdminSocketHook *m_version_hook = nullptr, *m_help_hook = nullptr,
-    *m_getdescs_hook = nullptr;
+  std::unique_ptr<AdminSocketHook> version_hook;
+  std::unique_ptr<AdminSocketHook> help_hook;
+  std::unique_ptr<AdminSocketHook> getdescs_hook;
 
   struct hook_info {
     AdminSocketHook* hook;