Skip to content

Commit

Permalink
Merge #673
Browse files Browse the repository at this point in the history
673: Fix two memory leaks in crossbeam-skiplist r=taiki-e a=sticnarf

Closes #671. Closes #672.

The first one is like a6de0ca, but the previous commit missed fixing `RefRange`.

The second problem is that `remove` increases the ref count but not returning the entry when the tower is not marked by the current thread. So the leak should be fixed if we always return the entry once the ref count is increased.

Co-authored-by: Yilin Chen <[email protected]>
  • Loading branch information
bors[bot] and sticnarf authored Mar 4, 2021
2 parents 447c6ae + bbe386e commit 2970aae
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions crossbeam-skiplist/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,9 +1123,8 @@ where
break;
}
}

return Some(entry);
}
return Some(entry);
}
}
}
Expand Down Expand Up @@ -1893,7 +1892,13 @@ where
pub fn next(&mut self, guard: &Guard) -> Option<RefEntry<'a, K, V>> {
self.parent.check_guard(guard);
self.head = match self.head {
Some(ref e) => e.next(guard),
Some(ref e) => {
let next_head = e.next(guard);
unsafe {
e.node.decrement(guard);
}
next_head
}
None => try_pin_loop(|| self.parent.lower_bound(self.range.start_bound(), guard)),
};
let mut finished = false;
Expand All @@ -1904,6 +1909,9 @@ where
};
if !below_upper_bound(&bound, h.key().borrow()) {
finished = true;
unsafe {
h.node.decrement(guard);
}
}
}
if finished {
Expand All @@ -1917,7 +1925,13 @@ where
pub fn next_back(&mut self, guard: &Guard) -> Option<RefEntry<'a, K, V>> {
self.parent.check_guard(guard);
self.tail = match self.tail {
Some(ref e) => e.prev(guard),
Some(ref e) => {
let next_tail = e.prev(guard);
unsafe {
e.node.decrement(guard);
}
next_tail
}
None => try_pin_loop(|| self.parent.upper_bound(self.range.start_bound(), guard)),
};
let mut finished = false;
Expand All @@ -1928,6 +1942,9 @@ where
};
if !above_lower_bound(&bound, t.key().borrow()) {
finished = true;
unsafe {
t.node.decrement(guard);
}
}
}
if finished {
Expand Down

0 comments on commit 2970aae

Please sign in to comment.