From a738af8f84580f7a17440227b7b5f8edc9fd43fb Mon Sep 17 00:00:00 2001 From: leipeng Date: Wed, 28 Dec 2016 18:25:50 -0800 Subject: [PATCH] db/pinned_iterators_manager.h: bugfix Summary: std::unique(beg, end) returns an iterator of unique_end, data behind unique_end should not be accessed. Closes https://github.com/facebook/rocksdb/pull/1726 Differential Revision: D4371076 Pulled By: IslamAbdelRahman fbshipit-source-id: 5564450 --- db/pinned_iterators_manager.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/db/pinned_iterators_manager.h b/db/pinned_iterators_manager.h index f8d64762c..9f814f0d9 100644 --- a/db/pinned_iterators_manager.h +++ b/db/pinned_iterators_manager.h @@ -59,13 +59,11 @@ class PinnedIteratorsManager { // Remove duplicate pointers std::sort(pinned_ptrs_.begin(), pinned_ptrs_.end()); - std::unique(pinned_ptrs_.begin(), pinned_ptrs_.end()); + auto unique_end = std::unique(pinned_ptrs_.begin(), pinned_ptrs_.end()); - for (size_t i = 0; i < pinned_ptrs_.size(); i++) { - assert(i == 0 || pinned_ptrs_[i].first != pinned_ptrs_[i - 1].first); - - void* ptr = pinned_ptrs_[i].first; - ReleaseFunction release_func = pinned_ptrs_[i].second; + for (auto i = pinned_ptrs_.begin(); i != unique_end; ++i) { + void* ptr = i->first; + ReleaseFunction release_func = i->second; release_func(ptr); } pinned_ptrs_.clear();