dermesser / leveldb-rs

A reimplementation of LevelDB in Rust (no bindings).
Other
521 stars 59 forks source link

thread 'main' has overflowed its stack #8

Open lijingwei9060 opened 3 years ago

lijingwei9060 commented 3 years ago

I got panic "thread 'main' has overflowed its stack" when try to run example/wirte-a-lot.

It happened when skipmap dropped.

The default drop of Node is recursive, it has a giant liked-list of nodes. The call back is tool large .

The following works.

impl Drop for Node {
    fn drop(&mut self) {
        // large object should drop
        if let Some(mut next) = self.next.take() {
            while let Some(child) = next.next.take() {
                next = child;
            }
        }
        unsafe {
            for skip in self.skips.iter_mut() {
                if let Some(mut next) = skip.take() {
                    while let Some(child) = (*next).next.take() {
                        next = Box::into_raw(child);
                    }
                }
            }
        }
    }
}