Open nhz2 opened 1 month ago
Thanks for letting us know about this issue! We really appreciate it, especially the example you provided for reproducing the bug and your potential solution.
@nhz2 Could you please clarify how exactly you suggest using GC.@preserve to solve this issue? My attempts didn’t yield the desired result. Since the data source is external, I was only able to protect it externally
using LibZip
archive = ZipArchive(; flags = LIBZIP_CREATE)
zip_data = rand(UInt8, 100_000_000);
GC.@preserve zip_data begin
write(archive, "greetings.txt", zip_data)
zip_data = nothing
GC.gc()
end
julia> close(archive)
true
I think one way is to save a reference to the thing that needs to be preserved in the ZipArchive
struct.
Then you can GC.@preserve
in any internal methods that use the data.
I've looked a bit at the docs for libzip and found https://libzip.org/documentation/zip_source_buffer.html
data must remain valid for the lifetime of the created source
But I'm not sure what exactly they mean by lifetime here. You may want to ask a question about this at https://github.com/nih-at/libzip/discussions
Describe the bug
Hello, While trying to test if this package is compatible with https://github.com/JuliaIO/ZipArchives.jl I occasionally got segmentation faults. I created a MWE below where I manually call
GC.gc()
.To Reproduce
Expected behavior
I think there is a missing call to
Base.cconvert
andGC.@preserve
somewhere.The functions must be used to ensure Julia doesn't free memory that a C library is still using.
Additional context