--- a/sys/net/zlib.c +++ b/sys/net/zlib.c @@ -785,9 +785,15 @@ uLong ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); if (s == Z_NULL) return Z_MEM_ERROR; strm->state = (struct internal_state FAR *)s; s->strm = strm; + /* + * deflateEnd() gates every cleanup path on s->status; the consumer + * zalloc (kernel kmalloc without M_ZERO) does not zero it, and the + * normal assignment only happens in deflateReset() after all + * sub-allocations succeed. An allocation failure before that makes + * deflateEnd() read uninitialized memory and leak every allocation. + */ + s->status = INIT_STATE; s->noheader = noheader;