liebharc / basic_dsp

Basic DSP vector operations for Rust.
Apache License 2.0
43 stars 5 forks source link

Memory Leak inside the VectorBox<B, T> #52

Closed VaynNecol closed 1 year ago

VaynNecol commented 1 year ago

https://github.com/liebharc/basic_dsp/blob/3df246ddf752082b2c25f8e0796f8ba11880eab7/benches/tools/mod.rs#LL175C2-L175C2

pub struct VectorBox<B, T>
where
    T: RealNumber,
{
    pub vector: *mut B,
    pub argument: *mut B,
    pub size: usize,
    pub buffer: SingleBuffer<T>,
}

impl<B, T> Drop for VectorBox<B, T>
where
    T: RealNumber,
{
    fn drop(&mut self) {
        unsafe {
            let _ = Box::from_raw(self.vector); // make sure that the vector is deleted
        }
    }
}

It appears that the field argument will be leaked because the Drop impl does not drop it.

@liebharc

liebharc commented 1 year ago

Hi @VaynNecol, that's true. Thanks for finding this. It will likely take me a bit to work on this lib again, but feel free to open a PR if you need a fix faster.

As this code is only part of the benchmark suite, I'm wondering how you found it. Did this impact your code in some way?

Ah sorry, didn't see your PR. Even more thanks then :).

liebharc commented 1 year ago

PRnhad been merged