From: Jason Dillaman Date: Wed, 6 Apr 2016 21:20:30 +0000 (-0400) Subject: journal: fix context memory leak when shutting down live replay X-Git-Tag: v10.1.2~32^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=408964eb09b2c36381f92ef668959f018c6503bb;p=ceph.git journal: fix context memory leak when shutting down live replay Signed-off-by: Jason Dillaman --- diff --git a/src/journal/ObjectPlayer.cc b/src/journal/ObjectPlayer.cc index e890dfa2d90b..db49d46ade27 100644 --- a/src/journal/ObjectPlayer.cc +++ b/src/journal/ObjectPlayer.cc @@ -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); }