Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix two memory leaks in crossbeam-skiplist #673

Merged
merged 2 commits into from
Mar 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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