]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crypto: fix unbalanced ceph::crypto::init/ceph::crypto:shutdown
authorYan, Zheng <zyan@redhat.com>
Wed, 5 Aug 2015 07:19:13 +0000 (15:19 +0800)
committerSage Weil <sage@redhat.com>
Thu, 13 Aug 2015 14:46:03 +0000 (10:46 -0400)
we may create a CephContext without calling common_init_finish(), then
delete the CephContext. In this case, ceph::crypto:init() is not called,
so CephContext::~CephContext() should not call ceph::crypto::shutdown().

Fixes: #12598
Signed-off-by: Yan, Zheng <zyan@redhat.com>
Reviewed-by: John Spray <john.spray@redhat.com>
src/common/ceph_context.cc
src/common/ceph_context.h
src/common/ceph_crypto.cc
src/common/common_init.cc

index 7a5c52bb0621fcd09147a5fb4354a82764e3a0c7..877dd539284ca0d86ea6c5f07cfe66060232d020 100644 (file)
@@ -399,6 +399,7 @@ CephContext::CephContext(uint32_t module_type_)
     _conf(new md_config_t()),
     _log(NULL),
     _module_type(module_type_),
+    _crypto_inited(false),
     _service_thread(NULL),
     _log_obs(NULL),
     _admin_socket(NULL),
@@ -507,7 +508,14 @@ CephContext::~CephContext()
 
   delete _crypto_none;
   delete _crypto_aes;
-  ceph::crypto::shutdown();
+  if (_crypto_inited)
+    ceph::crypto::shutdown();
+}
+
+void CephContext::init_crypto()
+{
+  ceph::crypto::init(this);
+  _crypto_inited = true;
 }
 
 void CephContext::start_service_thread()
index 95f6ea59bda3f5438dfef673a7885522fe938eae..da9e3f64a5d8749cecf1e4a10854ed70f9a6612c 100644 (file)
@@ -75,6 +75,9 @@ public:
   md_config_t *_conf;
   ceph::log::Log *_log;
 
+  /* init ceph::crypto */
+  void init_crypto();
+
   /* Start the Ceph Context's service thread */
   void start_service_thread();
 
@@ -137,6 +140,8 @@ private:
 
   uint32_t _module_type;
 
+  bool _crypto_inited;
+
   /* libcommon service thread.
    * SIGHUP wakes this thread, which then reopens logfiles */
   friend class CephContextServiceThread;
index 70f934bc901163b653a4042a2c41fc077028b0b8..de5a03b790abb0204daa7c649a022069ac821dff 100644 (file)
@@ -76,6 +76,7 @@ void ceph::crypto::init(CephContext *cct)
 void ceph::crypto::shutdown()
 {
   pthread_mutex_lock(&crypto_init_mutex);
+  assert(crypto_refs > 0);
   if (--crypto_refs == 0) {
     NSS_ShutdownContext(crypto_context);
     crypto_context = NULL;
index 90232c19a63daf0f569d9991a86c1b711d40c11e..a580309463f812450be50d4a821c71443a5616d9 100644 (file)
@@ -115,7 +115,7 @@ void complain_about_parse_errors(CephContext *cct,
  * same application. */
 void common_init_finish(CephContext *cct, int flags)
 {
-  ceph::crypto::init(cct);
+  cct->init_crypto();
 
   if (!(flags & CINIT_FLAG_NO_DAEMON_ACTIONS))
     cct->start_service_thread();