summaryrefslogtreecommitdiff
path: root/lib/content_encoding.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2011-08-21 13:15:34 +0200
committerYang Tse <yangsita@gmail.com>2011-08-21 13:24:46 +0200
commit1c400b4e5e8ec2e5f787c950e20209d0811b57e6 (patch)
tree75eedc7cd0105d7fca3e4895ed3bd48d06124e75 /lib/content_encoding.c
parent61ae7e9ce77af86a7290fca8bf73c9798f80845c (diff)
downloadcurl-1c400b4e5e8ec2e5f787c950e20209d0811b57e6.tar.gz
zlib: ensure user provided memory functions are used by zlib, when given
As a bonus, this lets our MemoryTracking subsystem track zlib operations. And also fixes a shortcut some zlib 1.2.x versions took using malloc() instead of calloc(), which would trigger memory debuggers warnings on memory being used without having been initialized.
Diffstat (limited to 'lib/content_encoding.c')
-rw-r--r--lib/content_encoding.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/content_encoding.c b/lib/content_encoding.c
index 84d76f4b9..3276ef988 100644
--- a/lib/content_encoding.c
+++ b/lib/content_encoding.c
@@ -49,6 +49,21 @@
#define COMMENT 0x10 /* bit 4 set: file comment present */
#define RESERVED 0xE0 /* bits 5..7: reserved */
+static voidpf
+zalloc_cb(voidpf opaque, unsigned int items, unsigned int size)
+{
+ (void) opaque;
+ /* not a typo, keep it calloc() */
+ return (voidpf) calloc(items, size);
+}
+
+static void
+zfree_cb(voidpf opaque, voidpf ptr)
+{
+ (void) opaque;
+ free(ptr);
+}
+
static CURLcode
process_zlib_error(struct connectdata *conn, z_stream *z)
{
@@ -159,6 +174,9 @@ Curl_unencode_deflate_write(struct connectdata *conn,
/* Initialize zlib? */
if(k->zlib_init == ZLIB_UNINIT) {
memset(z, 0, sizeof(z_stream));
+ z->zalloc = (alloc_func)zalloc_cb;
+ z->zfree = (free_func)zfree_cb;
+
if(inflateInit(z) != Z_OK)
return process_zlib_error(conn, z);
k->zlib_init = ZLIB_INIT;
@@ -266,6 +284,8 @@ Curl_unencode_gzip_write(struct connectdata *conn,
/* Initialize zlib? */
if(k->zlib_init == ZLIB_UNINIT) {
memset(z, 0, sizeof(z_stream));
+ z->zalloc = (alloc_func)zalloc_cb;
+ z->zfree = (free_func)zfree_cb;
if(strcmp(zlibVersion(), "1.2.0.4") >= 0) {
/* zlib ver. >= 1.2.0.4 supports transparent gzip decompressing */