]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/PrioritizedQueue: fix remove_by_class() corner case
authorSage Weil <sage@inktank.com>
Sat, 15 Mar 2014 03:26:04 +0000 (20:26 -0700)
committerSage Weil <sage@inktank.com>
Tue, 18 Mar 2014 20:16:05 +0000 (13:16 -0700)
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 <sage@inktank.com>
src/common/PrioritizedQueue.h

index d936d5d86c4fe1aae8c06eb4117d313460d8462d..28a9f7a4cd7fe509bbe914240125fe1019deb880 100644 (file)
@@ -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<pair<unsigned, T> >::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 {