-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom zlib hook seems to leak memory #44
Comments
Yes, lodepng is supposed to be freeing I'm tempted to change these adapters to use |
Please try 3.0.0-alpha.1 BTW, https://docs.rs/flate2/1.0.16/flate2/write/index.html has methods that work on io::Write. It also has a feature flag for cloudflare_zlib for AVX-accelerated encoding. |
I tried using it with zlib like this, but it produced corrupted png files: fn zlib_compressor_6(input: &[u8], output: &mut dyn std::io::Write, context: &CompressSettings) -> std::result::Result<(), lodepng::Error> {
zlib_compressor(input, output, context, 6)
}
fn zlib_compressor_9(input: &[u8], output: &mut dyn std::io::Write, context: &CompressSettings) -> std::result::Result<(), lodepng::Error> {
zlib_compressor(input, output, context, 9)
}
fn zlib_compressor(input: &[u8], output: &mut dyn std::io::Write, context: &CompressSettings, zlib_level: i32) -> std::result::Result<(), lodepng::Error>{
let target_buf_size = input.len() * 1001/1000 + 12;
let mut target = Vec::with_capacity(target_buf_size);
let mut compressed_size = target_buf_size as c_ulong;
unsafe {
compress2(target.as_mut_ptr(), &mut compressed_size, input.as_ptr(), input.len() as c_ulong, zlib_level);
}
target.truncate(compressed_size as usize);
if let Err(e) = output.write(&target){
return Err(lodepng::Error::new(1008));
}
Ok(())
} |
I also tried this with the same result: fn zlib_compressor(input: &[u8], output: &mut dyn std::io::Write, context: &CompressSettings, zlib_level: u32) -> std::result::Result<(), lodepng::Error>{
let mut compress = flate2::write::ZlibEncoder::new(output, flate2::Compression::new(zlib_level));
if let Err(e) = compress.write(&input){
return Err(lodepng::Error::new(1008));
}
if let Err(e) = compress.flush_finish(){
return Err(lodepng::Error::new(1009));
}
Ok(())
} What code are you using with this hook? |
Almost the same, but I'm calling |
Yeah, flush finish doesn't end the stream:
|
I tried switching to |
Oh, make sure to use |
That was it. Now I just need to figure out how to get both lodepng 3.0 and 2.6 to compile in the same assembly (DSSIM uses 2.6). Getting |
3.0 and 2.6 won't compile together, because they both export a C API. The other crates will have to upgrade. |
I've released lodepng 3.0.0 stable, and updated dssim to use it. |
Thank you so much!
…On Mon, Jul 6, 2020, 1:05 PM Kornel ***@***.***> wrote:
I've released lodepng 3.0.0 stable, and updated dssim to use it.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#44 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA2LH2VBR3TIKMRF6HHAIDR2IN75ANCNFSM4OOEK5JQ>
.
|
Given the following code
Valgrind reports that the memory allocated by libc::malloc is never freed.
Is lodepng supposed to be freeing the memory behind the
dest
pointer?The text was updated successfully, but these errors were encountered: