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

concurrent skiplist remove/replace may cause memory leaks #672

Closed
sticnarf opened this issue Mar 4, 2021 · 0 comments · Fixed by #673
Closed

concurrent skiplist remove/replace may cause memory leaks #672

sticnarf opened this issue Mar 4, 2021 · 0 comments · Fixed by #673

Comments

@sticnarf
Copy link
Contributor

sticnarf commented Mar 4, 2021

Code:

use crossbeam_skiplist::SkipSet;
use crossbeam_utils::thread;

use std::{iter, sync::Barrier};

fn run() {
    let set: SkipSet<i32> = iter::once(1).collect();
    let barrier = Barrier::new(2);
    thread::scope(|s| {
        s.spawn(|_| {
            barrier.wait();
            set.remove(&1);
            // A replace can also cause a leak
            // set.insert(1);
        });
        s.spawn(|_| {
            barrier.wait();
            set.remove(&1);
        });
    })
    .unwrap();
}

fn main() {
    for _ in 0..100 {
        run();
    }
}

Run with address sanitizer:

$ RUSTFLAGS='-Z sanitizer=address' cargo run
=================================================================
==1948257==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 384 byte(s) in 16 object(s) allocated from:
    #0 0x558113fa819d in malloc /rustc/llvm/src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
    #1 0x558113fea1ae in alloc::alloc::alloc::hcf88d30e57cf3e2a /home/yilin/.rustup/toolchains/nightly-2021-01-25-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/alloc.rs:86:14
    #2 0x55811401a395 in crossbeam_skiplist::base::Node$LT$K$C$V$GT$::alloc::he004a3fff4341a94 /home/yilin/Code/crossbeam/crossbeam-skiplist/src/base.rs:102:19
    #3 0x55811401d775 in crossbeam_skiplist::base::SkipList$LT$K$C$V$GT$::insert_internal::h829667128f83af99 /home/yilin/Code/crossbeam/crossbeam-skiplist/src/base.rs:885:25
    #4 0x55811401c774 in crossbeam_skiplist::base::SkipList$LT$K$C$V$GT$::get_or_insert::h5c252f8a1f57cf55 /home/yilin/Code/crossbeam/crossbeam-skiplist/src/base.rs:474:9
    #5 0x558113fd5421 in crossbeam_skiplist::set::SkipSet$LT$T$GT$::get_or_insert::h4032e246962d79f5 /home/yilin/Code/crossbeam/crossbeam-skiplist/src/set.rs:224:20
    #6 0x55811400b049 in core::iter::traits::iterator::Iterator::collect::hcf68d795ae4d7e7f /home/yilin/.rustup/toolchains/nightly-2021-01-25-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:1765:9
    #7 0x558113ffda53 in skiplist_demo::run::h8f93e4a3c1d06963 /home/yilin/Scratch/skiplist-demo/src/main.rs:7:29
    #8 0x558113ffe398 in skiplist_demo::main::ha4dda8363f53ed87 /home/yilin/Scratch/skiplist-demo/src/main.rs:24:9
    #9 0x558113fdacba in core::ops::function::FnOnce::call_once::ha570b3b78ebd326e /home/yilin/.rustup/toolchains/nightly-2021-01-25-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
    #10 0x558113fd78d6 in std::rt::lang_start::_$u7b$$u7b$closure$u7d$$u7d$::h079447501dfdfceb /home/yilin/.rustup/toolchains/nightly-2021-01-25-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:66:18

SUMMARY: AddressSanitizer: 384 byte(s) leaked in 16 allocation(s).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants