summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Le Blanc <lbarnaud@php.net>2008-08-02 02:36:25 +0000
committerArnaud Le Blanc <lbarnaud@php.net>2008-08-02 02:36:25 +0000
commit93b7cb0a0a4ba5053a4c3de9527e289b61980c3b (patch)
tree6c5611ca74ec807ed81e103d6837cd852ff31ec2
parent98b57957026f57c1d5f26c7a08eee78166fd9beb (diff)
downloadphp-git-93b7cb0a0a4ba5053a4c3de9527e289b61980c3b.tar.gz
MFH: Avoid leaks when zlib streams can not be closed properly.
-rw-r--r--ext/zlib/zlib.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index d78589e605..b593ade777 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -218,6 +218,19 @@ zend_module_entry php_zlib_module_entry = {
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)
{
@@ -553,8 +566,8 @@ static PHP_FUNCTION(gzdeflate)
}
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;
@@ -620,8 +633,8 @@ static PHP_FUNCTION(gzinflate)
}
plength = limit;
- stream.zalloc = (alloc_func) Z_NULL;
- stream.zfree = (free_func) Z_NULL;
+ stream.zalloc = php_zlib_alloc;
+ stream.zfree = php_zlib_free;
stream.opaque = Z_NULL;
stream.avail_in = data_len + 1; /* there is room for \0 */
stream.next_in = (Bytef *) data;
@@ -746,8 +759,8 @@ static int php_deflate_string(const char *str, uint str_length, char **newstr, u
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)) {
@@ -836,8 +849,8 @@ static PHP_FUNCTION(gzencode)
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;