Skip to content

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

@jingnz25

Description

@jingnz25

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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions