I'm currently working on a PNG decoder that has a C interface. My issue is that, once the decoding has finished, I leak all the PNG data which is stored as a
Vec<u8> and cast it into a
*mut c_void in order to hand it off to the other language. I also want to provide a function that frees the data I previously leaked, however, here is where I am stuck.
What I want to ask from the use of the interface is to provide only the
*mut c_void I returned previously and then I want to de-allocate that memory. How would I go about freeing the leaked memory from Rust?
One way that I have thought of is to reconstruct the
Vec<u8> and then let it
Drop, however, this requires knowing the capacity and length of the
Vec and this would require the ffi code to retain the dimensions of the image until the data must be freed. This seems very un-intuitive on the call-site.
Any suggestions on how I can go about doing this would be great!