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

Iterating a range of skipmap and insert back may cause mem leak #1178

Open
jingnz25 opened this issue Feb 10, 2025 · 2 comments
Open

Iterating a range of skipmap and insert back may cause mem leak #1178

jingnz25 opened this issue Feb 10, 2025 · 2 comments

Comments

@jingnz25
Copy link

crossbeam-skiplist = "0.1.3"

iter range from skipmap, clone (key, value)s and insert back to skipmap

Code:

use crossbeam_skiplist::SkipMap;

fn main() {
    let map = SkipMap::new();
    let _ = map.insert(vec![1u8], vec![1u8]);
    let _ = map.insert(vec![2], vec![2]);
    let _ = map.insert(vec![3], vec![3]);

    let kvs: Vec<(Vec<u8>, Vec<u8>)> = map
        .range(vec![1]..vec![3])
        .map(|e| (e.key().clone(), e.value().clone()))
        .collect();

    for (k, v) in kvs {
        map.insert(k, v);
    }
}

Run with address sanitizer:

RUSTFLAGS='-Z sanitizer=address' cargo run
   Compiling crossbeam-utils v0.8.21
   Compiling crossbeam-epoch v0.9.18
   Compiling crossbeam-skiplist v0.1.3
   Compiling test-skipmap v0.1.0 (/data/rust/test-skipmap)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.19s
     Running `target/debug/test-skipmap`

=================================================================
==1738483==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x55db3995997f  (/data/rust/test-skipmap/target/debug/test-skipmap+0x9997f) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)
    #1 0x55db39990faf  (/data/rust/test-skipmap/target/debug/test-skipmap+0xd0faf) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)
    #2 0x55db3999444e  (/data/rust/test-skipmap/target/debug/test-skipmap+0xd444e) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)
    #3 0x55db3999806f  (/data/rust/test-skipmap/target/debug/test-skipmap+0xd806f) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)
    #4 0x55db3998e3a9  (/data/rust/test-skipmap/target/debug/test-skipmap+0xce3a9) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)
    #5 0x55db3998a5ca  (/data/rust/test-skipmap/target/debug/test-skipmap+0xca5ca) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)
    #6 0x55db3998f8aa  (/data/rust/test-skipmap/target/debug/test-skipmap+0xcf8aa) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)
    #7 0x55db399c7191  (/data/rust/test-skipmap/target/debug/test-skipmap+0x107191) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)
    #8 0x55db39983dd8  (/data/rust/test-skipmap/target/debug/test-skipmap+0xc3dd8) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)
    #9 0x55db3998af5d  (/data/rust/test-skipmap/target/debug/test-skipmap+0xcaf5d) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)

Indirect leak of 2 byte(s) in 2 object(s) allocated from:
    #0 0x55db3995997f  (/data/rust/test-skipmap/target/debug/test-skipmap+0x9997f) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)
    #1 0x55db39990faf  (/data/rust/test-skipmap/target/debug/test-skipmap+0xd0faf) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)
    #2 0x55db39991240  (/data/rust/test-skipmap/target/debug/test-skipmap+0xd1240) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)
    #3 0x55db39990dea  (/data/rust/test-skipmap/target/debug/test-skipmap+0xd0dea) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)
    #4 0x55db3998f8aa  (/data/rust/test-skipmap/target/debug/test-skipmap+0xcf8aa) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)
    #5 0x55db399c7191  (/data/rust/test-skipmap/target/debug/test-skipmap+0x107191) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)
    #6 0x55db39983dd8  (/data/rust/test-skipmap/target/debug/test-skipmap+0xc3dd8) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)
    #7 0x55db3998af5d  (/data/rust/test-skipmap/target/debug/test-skipmap+0xcaf5d) (BuildId: 605573717e3f8eea538fe0d266711226d7071a30)

SUMMARY: AddressSanitizer: 66 byte(s) leaked in 3 allocation(s).
@taiki-e
Copy link
Member

taiki-e commented Feb 16, 2025

Thanks for the report! I wonder if this is the same issue as #540...

@jingnz25
Copy link
Author

jingnz25 commented Feb 17, 2025

Actually in my program there is a SkipMap in tokio RwLock, I spawned two threads do some operations in loop, one thread insert kvs to map, and clear map after every 100 insertions, another thread call range and clone kvs from map, then insert back to map. I observed a continuous memory increase while running the program.

I'm wodering why memory stays stable when I call iter instead of range in the above situation. And should I call crossbeam_epoch::pin().flush() after every operation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants