HaxeFoundation/hxcpp — pull request #8 by jgranick (2013-12-18 03:58:02+00:00)
Title: Zlib fixes

When performing a lot of zlib decompression, there began to problems such as "ZLib Error : -2" or crashing. Through further investigation, a few issues were found.

First, setting val_gc as NULL could crash if the object did not have a GC finalizer set, so we have a fix for that. In some cases, the zlib streams were also being released more than once, so we can guard against freeing a stream which has already been freed.

Finally, in some cases, garbage collection was trying to collect the zlib stream while the uncompress loop was still running. Understandably, asking zlib to inflate when the stream was already closed crashed the app. I'm not sure of the full reasons for this (it occurs primarily when many, many operations occur in a row on separate ByteArray objects) but to preserve stability, we have disabled the GC finalizer for zlib, allowing instead for the manual close() method to free the stream. This is called automatically by the Uncompress class, so it still seems safe, but perhaps determining the exact cause of this would be valuable.

Thanks