From 8bd89442aeb6f9fa7c2dea80b793aae4d70d50c9 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 14 Mar 2014 20:26:04 -0700 Subject: [PATCH] common/PrioritizedQueue: fix remove_by_class() corner case If i is the first entry, then setting cur = begin() sets us up to point at something that we are about to delete. Move the check to the end to avoid this. Backport: emperor, dumpling Signed-off-by: Sage Weil --- src/common/PrioritizedQueue.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/common/PrioritizedQueue.h b/src/common/PrioritizedQueue.h index d936d5d86c4fe..28a9f7a4cd7fe 100644 --- a/src/common/PrioritizedQueue.h +++ b/src/common/PrioritizedQueue.h @@ -171,11 +171,8 @@ class PrioritizedQueue { if (i == q.end()) return; size -= i->second.size(); - if (i == cur) { + if (i == cur) ++cur; - if (cur == q.end()) - cur = q.begin(); - } if (out) { for (typename list >::reverse_iterator j = i->second.rbegin(); @@ -185,6 +182,8 @@ class PrioritizedQueue { } } q.erase(i); + if (cur == q.end()) + cur = q.begin(); } void dump(Formatter *f) const { -- 2.39.5