Skip to content

Commit

Permalink
fix: ExtentTree use of invalidated iterator (#4416)
Browse files Browse the repository at this point in the history
Fixes accessing and invalidated iterator within ExtendTree
  • Loading branch information
kostasrim authored Jan 7, 2025
1 parent aaf33d5 commit e8f43d6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/core/extent_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void ExtentTree::Add(size_t start, size_t len) {
DCHECK_EQ(len_extents_.size(), extents_.size());

auto it = extents_.lower_bound(start);
optional<absl::btree_map<size_t, size_t>::iterator> prev_extent;
optional<size_t> prev_extent_key;

if (it != extents_.begin()) {
auto prev = it;
Expand All @@ -29,7 +29,7 @@ void ExtentTree::Add(size_t start, size_t len) {
prev->second += len;
start = prev->first;
len += prev_len;
prev_extent = prev;
prev_extent_key = prev->first;
}
}

Expand All @@ -44,8 +44,9 @@ void ExtentTree::Add(size_t start, size_t len) {
}

len_extents_.emplace(len, start);
if (prev_extent) {
(*prev_extent)->second = start + len;
if (prev_extent_key) {
DCHECK(extents_.find(*prev_extent_key) != extents_.end());
extents_[*prev_extent_key] = start + len;
} else {
extents_.emplace(start, start + len);
}
Expand Down

0 comments on commit e8f43d6

Please sign in to comment.