iliaa           Thu Aug 26 19:36:11 2004 EDT

  Modified files:              (Branch: PHP_4_3)
    /php-src/ext/zlib   zlib_fopen_wrapper.c 
  Log:
  MFH: Fixed a nasty resource/memory/disk-space leak when opening zlib files
  via wrapper stacking ala compress.zlib://http://...
  
  
http://cvs.php.net/diff.php/php-src/ext/zlib/zlib_fopen_wrapper.c?r1=1.33.2.6&r2=1.33.2.7&ty=u
Index: php-src/ext/zlib/zlib_fopen_wrapper.c
diff -u php-src/ext/zlib/zlib_fopen_wrapper.c:1.33.2.6 
php-src/ext/zlib/zlib_fopen_wrapper.c:1.33.2.7
--- php-src/ext/zlib/zlib_fopen_wrapper.c:1.33.2.6      Wed Jul 23 20:03:51 2003
+++ php-src/ext/zlib/zlib_fopen_wrapper.c       Thu Aug 26 19:36:11 2004
@@ -16,7 +16,7 @@
    |         Hartmut Holzgraefe <[EMAIL PROTECTED]>                          |
    +----------------------------------------------------------------------+
  */
-/* $Id: zlib_fopen_wrapper.c,v 1.33.2.6 2003/07/24 00:03:51 iliaa Exp $ */
+/* $Id: zlib_fopen_wrapper.c,v 1.33.2.7 2004/08/26 23:36:11 iliaa Exp $ */
 #define IS_EXT_MODULE
 #define _GNU_SOURCE
 
@@ -26,6 +26,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)
@@ -70,6 +71,10 @@
                        ret = gzclose(self->gz_file);
                        self->gz_file = NULL;
                }
+               if (self->stream) {
+                       php_stream_close(self->stream);
+                       self->stream = NULL;
+               }
        }
        efree(self);
 
@@ -95,7 +100,7 @@
 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 */
@@ -117,8 +122,9 @@
        
        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) {

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to