]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
journal: fix context memory leak when shutting down live replay
authorJason Dillaman <dillaman@redhat.com>
Wed, 6 Apr 2016 21:20:30 +0000 (17:20 -0400)
committerJason Dillaman <dillaman@redhat.com>
Wed, 6 Apr 2016 21:20:30 +0000 (17:20 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/journal/ObjectPlayer.cc

index e890dfa2d90b04c7ab1de4c14e7ee2ec0958e8ee..db49d46ade2782a9987621ff4e77ec4caf985941 100644 (file)
@@ -70,9 +70,15 @@ void ObjectPlayer::watch(Context *on_fetch, double interval) {
 void ObjectPlayer::unwatch() {
   ldout(m_cct, 20) << __func__ << ": " << m_oid << " unwatch" << dendl;
   Mutex::Locker timer_locker(m_timer_lock);
+
   cancel_watch();
 
-  m_watch_ctx = NULL;
+  Context *watch_ctx = nullptr;
+  std::swap(watch_ctx, m_watch_ctx);
+  if (watch_ctx != nullptr) {
+    delete watch_ctx;
+  }
+
   while (m_watch_in_progress) {
     m_watch_in_progress_cond.Wait(m_timer_lock);
   }
@@ -202,18 +208,17 @@ void ObjectPlayer::handle_watch_fetched(int r) {
   ldout(m_cct, 10) << __func__ << ": " << m_oid << " poll complete, r=" << r
                    << dendl;
 
-  Context *on_finish = NULL;
+  Context *on_finish = nullptr;
   {
     Mutex::Locker timer_locker(m_timer_lock);
     assert(m_watch_in_progress);
     if (r == -ENOENT) {
       r = 0;
     }
-    on_finish = m_watch_ctx;
-    m_watch_ctx = NULL;
+    std::swap(on_finish, m_watch_ctx);
   }
 
-  if (on_finish != NULL) {
+  if (on_finish != nullptr) {
     on_finish->complete(r);
   }