From 146383a21b932048030982f1c44d39781879ab41 Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Tue, 20 Jun 2017 18:51:34 +0800 Subject: [PATCH] osdc/Journaler: fix memory leak in Journaler::_issue_read() Contexts executed by _finish_flush() may call _issue_read(), _issue_read() may add new context to tail of waitfor_safe list. So _finish_flush() should first remove contexts from waitfor_safe, then execute the contexts. Fixes: http://tracker.ceph.com/issues/20338 Signed-off-by: "Yan, Zheng" --- src/osdc/Journaler.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/osdc/Journaler.cc b/src/osdc/Journaler.cc index ba18ff5534f..e2456c0b576 100644 --- a/src/osdc/Journaler.cc +++ b/src/osdc/Journaler.cc @@ -526,11 +526,16 @@ void Journaler::_finish_flush(int r, uint64_t start, ceph::real_time stamp) << dendl; // kick waiters <= safe_pos - while (!waitfor_safe.empty()) { - if (waitfor_safe.begin()->first > safe_pos) - break; - finish_contexts(cct, waitfor_safe.begin()->second); - waitfor_safe.erase(waitfor_safe.begin()); + if (!waitfor_safe.empty()) { + list ls; + while (!waitfor_safe.empty()) { + auto it = waitfor_safe.begin(); + if (it->first > safe_pos) + break; + ls.splice(ls.end(), it->second); + waitfor_safe.erase(it); + } + finish_contexts(cct, ls); } }