diff --git a/ext/zlib/tests/bug61139.phpt b/ext/zlib/tests/bug61139.phpt new file mode 100644 index 0000000000000..eaca00369bf07 --- /dev/null +++ b/ext/zlib/tests/bug61139.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #61139 (gzopen leaks when specifying invalid mode) +--SKIPIF-- + +--FILE-- +gz_file = gzdopen(dup(fd), mode); + self = emalloc(sizeof(*self)); self->stream = innerstream; - if (self->gz_file) { + self->gz_file = gzdopen(dup(fd), mode); + + if (self->gz_file) { stream = php_stream_alloc_rel(&php_stream_gzio_ops, self, 0, mode); if (stream) { stream->flags |= PHP_STREAM_FLAG_NO_BUFFER; return stream; } + gzclose(self->gz_file); } + + efree(self); if (options & REPORT_ERRORS) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "gzopen failed"); } - } else if (innerstream) { - php_stream_close(innerstream); } - } - if (stream) { - php_stream_close(stream); - } - - if (self) { - efree(self); + php_stream_close(innerstream); } - + return NULL; }