lbarnaud                Sat Aug  2 02:36:59 2008 UTC

  Modified files:              (Branch: PHP_5_2)
    /php-src/ext/zlib   zlib.c 
  Log:
  MFH: Avoid leaks when zlib streams can not be closed properly.
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/zlib/zlib.c?r1=1.183.2.6.2.6&r2=1.183.2.6.2.7&diff_format=u
Index: php-src/ext/zlib/zlib.c
diff -u php-src/ext/zlib/zlib.c:1.183.2.6.2.6 
php-src/ext/zlib/zlib.c:1.183.2.6.2.7
--- php-src/ext/zlib/zlib.c:1.183.2.6.2.6       Mon Dec 31 07:20:14 2007
+++ php-src/ext/zlib/zlib.c     Sat Aug  2 02:36:59 2008
@@ -19,7 +19,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: zlib.c,v 1.183.2.6.2.6 2007/12/31 07:20:14 sebastian Exp $ */
+/* $Id: zlib.c,v 1.183.2.6.2.7 2008/08/02 02:36:59 lbarnaud Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -156,6 +156,19 @@
 ZEND_GET_MODULE(php_zlib)
 #endif
 
+/* {{{ 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);
+}
+/* }}} */
+
 /* {{{ OnUpdate_zlib_output_compression */
 static PHP_INI_MH(OnUpdate_zlib_output_compression)
 {
@@ -491,8 +504,8 @@
        }
 
        stream.data_type = Z_ASCII;
-       stream.zalloc = (alloc_func) Z_NULL;
-       stream.zfree  = (free_func) Z_NULL;
+       stream.zalloc = php_zlib_alloc;
+       stream.zfree  = php_zlib_free;
        stream.opaque = (voidpf) Z_NULL;
 
        stream.next_in = (Bytef *) data;
@@ -566,8 +579,8 @@
          that should be enaugh for all real life cases 
        */
 
-       stream.zalloc = (alloc_func) Z_NULL;
-       stream.zfree = (free_func) Z_NULL;
+       stream.zalloc = php_zlib_alloc;
+       stream.zfree = php_zlib_free;
 
        do {
                length = plength ? plength : (unsigned long)data_len * (1 << 
factor++);
@@ -681,8 +694,8 @@
        int err;
 
        if (do_start) {
-               ZLIBG(stream).zalloc = Z_NULL;
-               ZLIBG(stream).zfree = Z_NULL;
+               ZLIBG(stream).zalloc = php_zlib_alloc;
+               ZLIBG(stream).zfree = php_zlib_free;
                ZLIBG(stream).opaque = Z_NULL;
 
                switch (ZLIBG(compression_coding)) {
@@ -771,8 +784,8 @@
                RETURN_FALSE;
        }
 
-       stream.zalloc = Z_NULL;
-       stream.zfree = Z_NULL;
+       stream.zalloc = php_zlib_alloc;
+       stream.zfree = php_zlib_free;
        stream.opaque = Z_NULL;
 
        stream.next_in = (Bytef *) data;



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

Reply via email to