]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mon: avoid using naked pointer
authorKefu Chai <kchai@redhat.com>
Fri, 15 Mar 2019 03:27:53 +0000 (11:27 +0800)
committerSage Weil <sage@redhat.com>
Fri, 15 Mar 2019 12:07:07 +0000 (07:07 -0500)
to save our trouble to delete auth_handler in the error handling paths

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/mon/Monitor.cc

index cd4cec304e069061aabb10a7bd441217bf7f76f7..7eeef1dad071931974310d91938e68514ce6f82f 100644 (file)
@@ -6184,8 +6184,8 @@ int Monitor::handle_auth_request(
     }
 
     // handler?
-    AuthServiceHandler *auth_handler = get_auth_service_handler(
-      auth_method, g_ceph_context, &key_server);
+    unique_ptr<AuthServiceHandler> auth_handler{get_auth_service_handler(
+      auth_method, g_ceph_context, &key_server)};
     if (!auth_handler) {
       dout(1) << __func__ << " auth_method " << auth_method << " not supported"
              << dendl;
@@ -6200,7 +6200,6 @@ int Monitor::handle_auth_request(
       if (mode < AUTH_MODE_MON ||
          mode > AUTH_MODE_MON_MAX) {
        dout(1) << __func__ << " invalid mode " << (int)mode << dendl;
-       delete auth_handler;
        return -EACCES;
       }
       assert(mode >= AUTH_MODE_MON && mode <= AUTH_MODE_MON_MAX);
@@ -6208,7 +6207,6 @@ int Monitor::handle_auth_request(
       decode(con->peer_global_id, p);
     } catch (buffer::error& e) {
       dout(1) << __func__ << " failed to decode, " << e.what() << dendl;
-      delete auth_handler;
       return -EACCES;
     }
 
@@ -6221,7 +6219,6 @@ int Monitor::handle_auth_request(
        dout(10) << __func__ << " entity " << entity_name << " method "
                 << auth_method << " not among supported "
                 << auth_cluster_required.get_supported_set() << dendl;
-       delete auth_handler;
        return -EOPNOTSUPP;
       }
     } else {
@@ -6229,7 +6226,6 @@ int Monitor::handle_auth_request(
        dout(10) << __func__ << " entity " << entity_name << " method "
                 << auth_method << " not among supported "
                 << auth_cluster_required.get_supported_set() << dendl;
-       delete auth_handler;
        return -EOPNOTSUPP;
       }
     }
@@ -6242,7 +6238,6 @@ int Monitor::handle_auth_request(
       con->peer_global_id = authmon()->_assign_global_id();
       if (!con->peer_global_id) {
        dout(1) << __func__ << " failed to assign global_id" << dendl;
-       delete auth_handler;
        return -EBUSY;
       }
       dout(10) << __func__ << "  assigned global_id " << con->peer_global_id
@@ -6251,7 +6246,7 @@ int Monitor::handle_auth_request(
 
     // set up partial session
     s = new MonSession(con);
-    s->auth_handler = auth_handler;
+    s->auth_handler = auth_handler.release();
     con->set_priv(RefCountedPtr{s, false});
 
     r = s->auth_handler->start_session(