RazrFalcon / rctree

A "DOM-like" tree implemented using reference counting
MIT License
36 stars 10 forks source link

Stack overflow on drop, when no parents and many following siblings #10

Open lo48576 opened 5 years ago

lo48576 commented 5 years ago
#[test]
fn stack_overflow_siblings() {
    let mut prev_sibling = Node::new(1);
    for _ in 0..200_000 {
        let node = Node::new(1);
        prev_sibling.insert_before(node.clone());
        prev_sibling = node;
    }
}

This is very similar to stack_overflow() test, but this ends up in stack overflow.

Current Drop impl of NodeData<T> detaches descendants before they are dropped, but do nothing special to following siblings. If they have parent, they would be detached by parent's NodeData<T>::drop(), so this does not matter. However, rctree allows root node to have siblings, and in this case siblings are not detached beforehand and dropped recursively.

RazrFalcon commented 5 years ago

Yes, this should be handled.