lbarnaud                Sat Aug  2 02:36:14 2008 UTC

  Modified files:              
    /php-src/ext/zlib   zlib.c 
  Log:
  Avoid leaks when zlib streams can not be closed properly.
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/zlib/zlib.c?r1=1.219&r2=1.220&diff_format=u
Index: php-src/ext/zlib/zlib.c
diff -u php-src/ext/zlib/zlib.c:1.219 php-src/ext/zlib/zlib.c:1.220
--- php-src/ext/zlib/zlib.c:1.219       Thu Jul  3 12:21:25 2008
+++ php-src/ext/zlib/zlib.c     Sat Aug  2 02:36:14 2008
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: zlib.c,v 1.219 2008/07/03 12:21:25 felipe Exp $ */
+/* $Id: zlib.c,v 1.220 2008/08/02 02:36:14 lbarnaud Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #      include "config.h"
@@ -36,6 +36,19 @@
 
 ZEND_DECLARE_MODULE_GLOBALS(zlib);
 
+/* {{{ Memory management wrappers */
+
+static voidpf php_zlib_alloc(voidpf opaque, uInt items, uInt size)
+{
+       return (voidpf)safe_emalloc(items, size, 0);
+}
+
+static void php_zlib_free(voidpf opaque, voidpf address)
+{
+       efree((void*)address);
+}
+/* }}} */
+
 /* {{{ php_zlib_output_conflict_check() */
 int php_zlib_output_conflict_check(zval *handler_name TSRMLS_DC)
 {
@@ -104,12 +117,16 @@
 php_output_handler *php_zlib_output_handler_init(zval *handler_name, size_t 
chunk_size, int flags TSRMLS_DC)
 {
        php_output_handler *h = NULL;
+       php_zlib_context   *ctx;
        
        if (!ZLIBG(output_compression)) {
                ZLIBG(output_compression) = chunk_size ? chunk_size : 
PHP_OUTPUT_HANDLER_DEFAULT_SIZE;
        }
        if ((h = php_output_handler_create_internal(handler_name, 
php_zlib_output_handler, chunk_size, flags TSRMLS_CC))) {
-               php_output_handler_set_context(h, ecalloc(1, 
sizeof(php_zlib_context)), php_zlib_output_handler_dtor TSRMLS_CC);
+               ctx = (php_zlib_context *) ecalloc(1, sizeof(php_zlib_context));
+               ctx->Z.zalloc = php_zlib_alloc;
+               ctx->Z.zfree = php_zlib_free;
+               php_output_handler_set_context(h, ctx, 
php_zlib_output_handler_dtor TSRMLS_CC);
        }
        
        return h;
@@ -264,6 +281,8 @@
        z_stream Z;
        
        memset(&Z, 0, sizeof(z_stream));
+       Z.zalloc = php_zlib_alloc;
+       Z.zfree = php_zlib_free;
        
        if (Z_OK == (status = deflateInit2(&Z, level, Z_DEFLATED, encoding, 
MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) {
                *out_len = PHP_ZLIB_BUFFER_SIZE_GUESS(in_len);
@@ -347,6 +366,9 @@
        z_stream Z;
        
        memset(&Z, 0, sizeof(z_stream));
+       Z.zalloc = php_zlib_alloc;
+       Z.zfree = php_zlib_free;
+
        if (in_len) {
 retry_raw_inflate:
                status = inflateInit2(&Z, encoding);



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

Reply via email to