From: Nikita Popov Date: Sun, 19 Feb 2012 14:39:29 +0000 (+0000) Subject: Fix bug #61139 gzopen leaks when specifying invalid mode X-Git-Tag: php-5.5.0alpha1~521 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ecd13fd184ab46136d893338748fcda6c1458c7f;p=php Fix bug #61139 gzopen leaks when specifying invalid mode Needs to be merged to 5.4. --- diff --git a/ext/zlib/tests/bug61139.phpt b/ext/zlib/tests/bug61139.phpt new file mode 100644 index 0000000000..eaca00369b --- /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; }