]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: postpone cct deletion 11659/head
authorKefu Chai <kchai@redhat.com>
Wed, 26 Oct 2016 09:21:41 +0000 (17:21 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 26 Oct 2016 15:20:10 +0000 (23:20 +0800)
RefCountedObject::put() prints log using cct, but RadosClient
relinquishes the reference to cct too early, so when its
`RefCountedObject` member variables print log when they are
destructed, the cct is already freed. hence we have a segfault.

to address this problem, we need postpone destructure of it after all
other RefCountedObject member variables are destroyed.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/librados/RadosClient.cc
src/librados/RadosClient.h

index f73ff4ee89c52701b9034f6b72e58f95b5627433..2300f62058bfbf3096692d378816b13779f9b0ea 100644 (file)
@@ -65,6 +65,7 @@ bool librados::RadosClient::ms_get_authorizer(int dest_type,
 
 librados::RadosClient::RadosClient(CephContext *cct_)
   : Dispatcher(cct_->get()),
+    cct_deleter{cct_, [](CephContext *p) {p->put();}},
     conf(cct_->_conf),
     state(DISCONNECTED),
     monclient(cct_),
@@ -431,7 +432,6 @@ librados::RadosClient::~RadosClient()
     delete messenger;
   if (objecter)
     delete objecter;
-  cct->put();
   cct = NULL;
 }
 
index a88da49ba7403f63ebef5075f133322b78714d83..557d14f241ea87c318ad6702833397f7e844120b 100644 (file)
@@ -37,6 +37,9 @@ class AioCompletionImpl;
 
 class librados::RadosClient : public Dispatcher
 {
+  std::unique_ptr<CephContext,
+                 std::function<void(CephContext*)> > cct_deleter;
+
 public:
   using Dispatcher::cct;
   md_config_t *conf;