Is this mem leak or am I doing something wrong?

It's seems like I have a mem leak while using scoped-pool:

    ==12569== 560 bytes in 14 blocks are indirectly lost in loss record 7 of 15 
    ==12569== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) 
    ==12569== by 0x2ACE3B: alloc::alloc::alloc (alloc.rs:82) 
    ==12569== by 0x2ACDAB: alloc::alloc::exchange_malloc (alloc.rs:204) 
    ==12569== by 0x2AC2A6: new<crossbeam::sync::ms_queue::Node<scoped_pool::PoolMessage>> (boxed.rs:116) 
    ==12569== by 0x2AC2A6: crossbeam::mem::epoch::Owned<T>::new (mod.rs:153) 
    ==12569== by 0x2A222A: crossbeam::sync::ms_queue::MsQueue<T>::push::Cache<T>::into_node (ms_queue.rs:115) 
    ==12569== by 0x2A25E6: crossbeam::sync::ms_queue::MsQueue<T>::push (ms_queue.rs:153) 
    ==12569== by 0x2A943B: scoped_pool::Pool::run_thread (lib.rs:172) 
    ==12569== by 0x2A92CD: scoped_pool::Pool::expand::{{closure}} (lib.rs:160) 
    ==12569== by 0x2A5CBA: std::sys_common::backtrace::__rust_begin_short_backtrace (backtrace.rs:77) 
    ==12569== by 0x2AAC9D: std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}} (mod.rs:470) 
    ==12569== by 0x2A5C2D: <std::panic::AssertUnwindSafe<F> as     core::ops::function::FnOnce<()>>::call_once (panic.rs:315) 
    ==12569== by 0x2A4DA4: std::panicking::try::do_call (panicking.rs:296) 
    ==12569== .... 
    ==12569== 
    ==12569== LEAK SUMMARY: 
    ==12569== definitely lost: 560 bytes in 14 blocks 
    ==12569== indirectly lost: 560 bytes in 14 blocks 
    ==12569== possibly lost: 0 bytes in 0 blocks 
    ==12569== still reachable: 95,976 bytes in 579 blocks 
    ==12569== suppressed: 0 bytes in 0 blocks 
    ==12569== 
    ==12569== For counts of detected and suppressed errors, rerun with: -v 
    ==12569== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

I use scoped-pool as follows:

pub fn next_generation_par(mut populations: HashMap<usize, Population>, dsr: &DataSetDir) -> HashMap<usize, Population> {
    let (sender, receiver) = channel();
    let pool = Pool::new(16);
    pool.scoped(|scope| {
        for (_, mut population) in populations {
            let thread_sender = sender.clone();
            scope.execute(move || {
                let population = // actual work 
                if let Result::Err(err) = thread_sender.send(population) {
                    panic!("Unable to send: {:?}", err);
                }
            });
        }
    });
    drop(sender);
    pool.shutdown();
    let populations: Vec<Population> = receiver.iter().collect();

Does this look correct?

Thanks
Lukasz

Welcome to the forum! Note that you can use three backticks (```) to post formatted code here. For example:

```rust
let (sender, receiver) = channel();
let pool = Pool::new(16);
```

Will display as:

let (sender, receiver) = channel();
let pool = Pool::new(16);