]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crypto: fix unbalanced ceph::crypto::init/ceph::crypto:shutdown 5887/head
authorYan, Zheng <zyan@redhat.com>
Wed, 5 Aug 2015 07:19:13 +0000 (15:19 +0800)
committerAbhishek Varshney <abhishek.varshney@flipkart.com>
Fri, 11 Sep 2015 11:01:47 +0000 (16:31 +0530)
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>
(cherry picked from commit 98a85ec6464d8ec3fc7f0c647ac97c8cf002ebe2)

src/common/ceph_context.cc
src/common/ceph_context.h
src/common/ceph_crypto.cc
src/common/common_init.cc

index 39c7f4e1907eade36ecb3d921c6b692b1257e199..50346edf2ace6a227b6f32fbf241a517db4d814c 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 91810aa09baf3c33f0955689845178f21b6a1e48..a9ffde04eb35b6eaf3481dc5e4624cbb37a0432d 100644 (file)
@@ -77,6 +77,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();
 
@@ -139,6 +142,8 @@ private:
 
   uint32_t _module_type;
 
+  bool _crypto_inited;
+
   /* libcommon service thread.
    * SIGHUP wakes this thread, which then reopens logfiles */
   friend class CephContextServiceThread;
index 041fedad24061c04c17ab2147191aa1089c1dc0b..f15ef09160b22dd7cbe2fee347b2abae123a09c0 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();