I would double-check the ZLIB binding code that you have, to make sure that everything is correct. This looks suspiciously like a memory-corruption issue, which tends to happen when Nim bindnigs don't accurately represent the functions/structures they are wrapping.
You _[might](https://forum.nim-lang.org/postActivity.xml#might) have some luck with defining the symbol 'checkAbi' (so `-d:checkAbi`) to insert C binding checks.
