aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
parent61ae7e9ce77af86a7290fca8bf73c9798f80845c (diff)
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 'src')
-rw-r--r--src/mkhelp.pl17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/mkhelp.pl b/src/mkhelp.pl
index e9de8429d..d09d6c508 100644
--- a/src/mkhelp.pl
+++ b/src/mkhelp.pl
@@ -133,7 +133,6 @@ print <<HEAD
* NEVER EVER edit this manually, fix the mkhelp.pl script instead!
* Generation time: $now
*/
-#include "setup.h"
#ifdef USE_MANUAL
#include "hugehelp.h"
HEAD
@@ -141,6 +140,9 @@ HEAD
if($c) {
print <<HEAD
#include <zlib.h>
+#if defined(CURLDEBUG) && defined(CURLTOOLDEBUG)
+#include "memdebug.h"
+#endif
static const unsigned char hugehelpgz[] = {
/* This mumbo-jumbo is the huge help text compressed with gzip.
Thanks to this operation, the size of this data shrunk from $gzip
@@ -165,6 +167,17 @@ HEAD
print <<EOF
#define BUF_SIZE 0x10000
+static voidpf zalloc_func(voidpf opaque, unsigned int items, unsigned int size)
+{
+ (void) opaque;
+ /* not a typo, keep it calloc() */
+ return (voidpf) calloc(items, size);
+}
+static void zfree_func(voidpf opaque, voidpf ptr)
+{
+ (void) opaque;
+ free(ptr);
+}
/* Decompress and send to stdout a gzip-compressed buffer */
void hugehelp(void)
{
@@ -178,6 +191,8 @@ void hugehelp(void)
headerlen = 10;
memset(&z, 0, sizeof(z_stream));
+ z.zalloc = (alloc_func)zalloc_func;
+ z.zfree = (free_func)zfree_func;
z.avail_in = (unsigned int)(sizeof(hugehelpgz) - headerlen);
z.next_in = (unsigned char *)hugehelpgz + headerlen;