yuvadm / bchlib

Rust bindings for BCH encoding/decoding library, based on the bch_codec fork
GNU General Public License v2.0
1 stars 3 forks source link

Missing `Drop` implementation #1

Open icmccorm opened 9 months ago

icmccorm commented 9 months ago

I noticed that BCH in bchlib/src/lib.rs calls ffi::init_bch(..), but it doesn't seem to have a destructor that would call the corresponding ffi::free_bch(..) when the object leaves scope. I tried implementing Drop for this struct, but oddly enough I'm getting an invalid pointer from free() on multiple systems.

icmccorm commented 8 months ago

This also occurs in bchlib-sys in the test it_works

#[test]
fn it_works() {
  unsafe {
    let _c = init_bch(5, 2, 37);
  }
}

Since free_bch is never called, this memory is leaked.