From: Sage Weil Date: Sat, 15 Mar 2014 03:26:04 +0000 (-0700) Subject: common/PrioritizedQueue: fix remove_by_class() corner case X-Git-Tag: v0.79~109^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8bd89442aeb6f9fa7c2dea80b793aae4d70d50c9;p=ceph.git 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 --- diff --git a/src/common/PrioritizedQueue.h b/src/common/PrioritizedQueue.h index d936d5d86c4f..28a9f7a4cd7f 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 {