Skip to content

Commit a090e1f

Browse files
author
Ulrik Sverdrup
committed
linked_list: Use a safe loop in Drop
1 parent da0d452 commit a090e1f

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

src/libcollections/linked_list.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -626,21 +626,13 @@ impl<T> LinkedList<T> {
626626
#[stable(feature = "rust1", since = "1.0.0")]
627627
impl<T> Drop for LinkedList<T> {
628628
fn drop(&mut self) {
629-
// Dissolve the linked_list in backwards direction
629+
// Dissolve the linked_list in a loop.
630630
// Just dropping the list_head can lead to stack exhaustion
631631
// when length is >> 1_000_000
632-
let mut tail = self.list_tail;
633-
loop {
634-
match tail.resolve() {
635-
None => break,
636-
Some(prev) => {
637-
prev.next.take(); // release Box<Node<T>>
638-
tail = prev.prev;
639-
}
640-
}
632+
while let Some(mut head_) = self.list_head.take() {
633+
self.list_head = head_.next.take();
641634
}
642635
self.length = 0;
643-
self.list_head = None;
644636
self.list_tail = Rawlink::none();
645637
}
646638
}

0 commit comments

Comments
 (0)