diff options
author | Ilia Alshanetsky <iliaa@php.net> | 2004-08-26 23:36:05 +0000 |
---|---|---|
committer | Ilia Alshanetsky <iliaa@php.net> | 2004-08-26 23:36:05 +0000 |
commit | ee8a0fc8f8155a4b69fbaec029cf16134dae74f2 (patch) | |
tree | 5a8520e2fa79265fa1ee2b0ce236a44a9a523378 /ext/zlib/zlib_fopen_wrapper.c | |
parent | ec4f576cb38ac94a0203191ebc360e0c0a73f8e2 (diff) | |
download | php-git-ee8a0fc8f8155a4b69fbaec029cf16134dae74f2.tar.gz |
Fixed a nasty resource/memory/disk-space leak when opening zlib files
via wrapper stacking ala compress.zlib://http://...
Diffstat (limited to 'ext/zlib/zlib_fopen_wrapper.c')
-rw-r--r-- | ext/zlib/zlib_fopen_wrapper.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/ext/zlib/zlib_fopen_wrapper.c b/ext/zlib/zlib_fopen_wrapper.c index a1e897b7af..69a5a9a09e 100644 --- a/ext/zlib/zlib_fopen_wrapper.c +++ b/ext/zlib/zlib_fopen_wrapper.c @@ -27,6 +27,7 @@ struct php_gz_stream_data_t { gzFile gz_file; + php_stream *stream; }; static size_t php_gziop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) @@ -74,6 +75,10 @@ static int php_gziop_close(php_stream *stream, int close_handle TSRMLS_DC) ret = gzclose(self->gz_file); self->gz_file = NULL; } + if (self->stream) { + php_stream_close(self->stream); + self->stream = NULL; + } } efree(self); @@ -100,7 +105,7 @@ php_stream_ops php_stream_gzio_ops = { php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) { - struct php_gz_stream_data_t *self; + struct php_gz_stream_data_t *self = {0}; php_stream *stream = NULL, *innerstream = NULL; /* sanity check the stream: it can be either read-only or write-only */ @@ -124,8 +129,9 @@ php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, char *path, char *mod if (innerstream) { int fd; - if (SUCCESS == php_stream_cast(innerstream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_RELEASE, (void **) &fd, REPORT_ERRORS)) { + if (SUCCESS == php_stream_cast(innerstream, PHP_STREAM_AS_FD, (void **) &fd, REPORT_ERRORS)) { self->gz_file = gzdopen(fd, mode); + self->stream = innerstream; if (self->gz_file) { stream = php_stream_alloc_rel(&php_stream_gzio_ops, self, 0, mode); if (stream) { |