mirror of
https://github.com/apple/swift-nio-extras
synced 2026-11-22 04:30:42 +00:00
### Motivation: zlib stores the address of `z_stream` in its internal state and expects that address to remain stable across calls. Storing `z_stream` inline in movable Swift value types does not provide that guarantee and can cause `Z_STREAM_ERROR` during cleanup. Fixes #308. ### Modifications: - Make the internal compressor and decompressor reference owners of separately allocated `z_stream` storage. - Pass the stable pointer to every zlib initialization, processing, and cleanup call. - Keep lifecycle state with the pointer owner and make conditional cleanup idempotent. - Add regression tests covering failed initialization recovery, multiple compression and decompression calls, repeated lifecycles, and deallocation cleanup. ### Result: zlib observes the same `z_stream` address for each complete lifecycle, while stream cleanup remains single-owner and safe against repeated shutdown.