From db79d9c4c5a8b7ddbf800512d33b1f68dc69c8a4 Mon Sep 17 00:00:00 2001 From: K Pamnany Date: Thu, 2 Nov 2023 20:17:52 -0400 Subject: [PATCH] Preserve `out_buffer` in `process()` --- src/lz4_compression.jl | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/lz4_compression.jl b/src/lz4_compression.jl index f5064b3..cc68f76 100644 --- a/src/lz4_compression.jl +++ b/src/lz4_compression.jl @@ -154,18 +154,20 @@ function TranscodingStreams.process( out_buffer = Vector{UInt8}(undef, LZ4_compressBound(data_size)) unsafe_copyto!(in_buffer, input.ptr, data_size) - compressed_size = LZ4_compress_fast_continue( - codec.streamptr, - in_buffer, - pointer(out_buffer), - data_size, - length(out_buffer), - codec.acceleration, - ) - - checkbounds(output, compressed_size + CINT_SIZE) - writeint(output, compressed_size) - unsafe_copyto!(output.ptr + CINT_SIZE, pointer(out_buffer), compressed_size) + GC.@preserve out_buffer begin + compressed_size = LZ4_compress_fast_continue( + codec.streamptr, + in_buffer, + pointer(out_buffer), + data_size, + length(out_buffer), + codec.acceleration, + ) + + checkbounds(output, compressed_size + CINT_SIZE) + writeint(output, compressed_size) + unsafe_copyto!(output.ptr + CINT_SIZE, pointer(out_buffer), compressed_size) + end return (data_size, compressed_size + CINT_SIZE, :ok) catch err