cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: issue #33 in TODO-RELEASE

From: Seshubabu Pasam <pasam_at_seshubabu.com>
Date: Thu, 06 May 2004 20:38:23 -0700

Here is the patch for issue #33. Here is what I did:

1.) Added --enable-memcallback flag. This has no effect when
--enable-debug is used.

2.) Added curl_set_mem_callbacks function in curl.h when
CURL_MEMCALLBACK CPPFLAG is set (will be set, if compiled with
--enable-memcallback) This function can be called with user defined
memory management routines.

3.) Replaced malloc/free/realloc/strdup with
curl_malloc/curl_free/curl_realloc/curl_strdup respectively in all .c
files in lib and src folders.

4.) url.c has 2 'free' calls that are not changed, since the memory is
allocated externally in libidn.

5.) Replaced all calloc's with curl_malloc and memset.

6.) When either debug or memcallback are enabled, curl_malloc... are
just macros to malloc...

7.) When debug is enabled, curl_malloc ... are also macros, but point to
curl_domalloc ... implemented in memdebug.c

8.) When memcallback is enabled, the curl_set_mem_callback function is
compiled in. curl_malloc ... are function pointers that can be replaced
with user defined functions byt calling the callback function.

9.) I am not sure if this is problematic: I removed "curl_free" function
from curl.h. I did not understand why it is there in the first place. It
is just a wrapper around 'free'. It is not consistently used in the curl
code. I am not sure, what functionality it is supposed to provide to the
libCurl library users. Let me know if this is an issue, I will add it
back and rename my curl_free macro to something else....

Regards
-Seshubabu Pasam

Daniel Stenberg wrote:
> On Thu, 6 May 2004, Daniel Stenberg wrote:
>
>
>>everything I receive with pretty restrictive filters. I think your mail
>>must've been caught in there somehow.
>
>
> No, I found it! :-) I get quite a large amount of valid mails too... and I
> should learn to check all my mails before I talk.
>
> Sorry.
>
> But I still would like you to post the patch to the list for discussion.
>

Index: configure.ac
===================================================================
RCS file: /repository/curl/configure.ac,v
retrieving revision 1.81
diff -u -3 -H -r1.81 configure.ac
--- configure.ac 5 May 2004 10:26:51 -0000 1.81
+++ configure.ac 6 May 2004 07:15:57 -0000
@@ -1363,6 +1363,27 @@
        AC_MSG_RESULT(no)
 )
 
+dnl ************************************************************
+dnl Support for memory callback functions.
+dnl
+AC_MSG_CHECKING([whether to enable memory related callback function support or not])
+AC_ARG_ENABLE(memcallback,
+AC_HELP_STRING([--enable-memcallback],[Enable support for memory callback functions])
+AC_HELP_STRING([--disable-memcallback],[Disable support for memory callback functions]),
+[ case "$enableval" in
+ no)
+ AC_MSG_RESULT(no)
+ ;;
+ *) AC_MSG_RESULT(yes)
+
+ CPPFLAGS="$CPPFLAGS -DCURL_MEMCALLBACK"
+
+ ;;
+ esac
+ ],
+ AC_MSG_RESULT(no)
+)
+
 AC_CONFIG_FILES([Makefile \
            docs/Makefile \
            docs/examples/Makefile \
Index: include/curl/curl.h
===================================================================
RCS file: /repository/curl/include/curl/curl.h,v
retrieving revision 1.251
diff -u -3 -H -r1.251 curl.h
--- include/curl/curl.h 4 May 2004 08:24:13 -0000 1.251
+++ include/curl/curl.h 6 May 2004 07:16:37 -0000
@@ -993,16 +993,6 @@
 char *curl_unescape(const char *string, int length);
 
 /*
- * NAME curl_free()
- *
- * DESCRIPTION
- *
- * Provided for de-allocation in the same translation unit that did the
- * allocation. Added in libcurl 7.10
- */
-void curl_free(void *p);
-
-/*
  * NAME curl_global_init()
  *
  * DESCRIPTION
@@ -1261,6 +1251,34 @@
  */
 const char *curl_share_strerror(CURLSHcode);
 
+#ifdef CURL_MEMCALLBACK
+/*
+ * The following typedef's are signatures of malloc, free, realloc and strdup
+ * respectively. Function pointers of these types can be passed to
+ * curl_set_memory_callbacks function to set the memory management callback
+ * routines.
+ */
+typedef void *(*curlMallocFunc) (size_t size);
+typedef void (*curlFreeFunc) (void *ptr);
+typedef void *(*curlReallocFunc)(void *ptr, size_t size);
+typedef char *(*curlStrdupFunc) (const char *str);
+
+/*
+ * NAME curl_set_memory_callbacks()
+ *
+ * DESCRIPTION
+ * Set user defined memory management callback functions. Users can implement
+ * memory management routines to check for memory leaks, check for mis-use of
+ * the curl etc. This function can be used to register used defined callback
+ * functions and curl with call these function instead of system memory
+ * management routines like malloc, free etc. This method returns '0', if
+ * the input arguments are valid. '-1' is returned, if any of the input
+ * function pointers are not valid.
+ */
+int curl_set_memory_callbacks(curlMallocFunc m,curlFreeFunc f,
+ curlReallocFunc r,curlStrdupFunc s );
+#endif /* CURL_MEMCALLBACK */
+
 #ifdef __cplusplus
 }
 #endif
Index: lib/base64.c
===================================================================
RCS file: /repository/curl/lib/base64.c,v
retrieving revision 1.28
diff -u -3 -H -r1.28 base64.c
--- lib/base64.c 1 Mar 2004 12:54:59 -0000 1.28
+++ lib/base64.c 6 May 2004 07:16:40 -0000
@@ -42,9 +42,7 @@
 
 #include "base64.h"
 
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 static void decodeQuantum(unsigned char *dest, const char *src)
 {
@@ -134,7 +132,7 @@
   if(0 == insize)
     insize = strlen(indata);
 
- base64data = output = (char*)malloc(insize*4/3+4);
+ base64data = output = (char*)curl_malloc(insize*4/3+4);
   if(NULL == output)
     return 0;
 
@@ -209,7 +207,7 @@
   fprintf(stderr, "%d\n", base64Len);
   fprintf(stdout, "%s", base64);
 
- free(base64); free(data);
+ curl_free(base64); curl_free(data);
   return 0;
 }
 #endif
@@ -234,7 +232,7 @@
   int i, j;
 
   base64 = (char *)suck(&base64Len);
- data = (unsigned char *)malloc(base64Len * 3/4 + 8);
+ data = (unsigned char *)curl_malloc(base64Len * 3/4 + 8);
   dataLen = Curl_base64_decode(base64, data);
 
   fprintf(stderr, "%d\n", dataLen);
@@ -257,7 +255,7 @@
     puts("");
   }
 
- free(base64); free(data);
+ curl_free(base64); curl_free(data);
   return 0;
 }
 #endif
@@ -273,7 +271,7 @@
 
   do {
     cursize *= 2;
- buf = (unsigned char *)realloc(buf, cursize);
+ buf = (unsigned char *)curl_realloc(buf, cursize);
     memset(buf + len, 0, cursize - len);
     lastread = fread(buf + len, 1, cursize - len, stdin);
     len += lastread;
Index: lib/connect.c
===================================================================
RCS file: /repository/curl/lib/connect.c,v
retrieving revision 1.99
diff -u -3 -H -r1.99 connect.c
--- lib/connect.c 27 Apr 2004 13:56:23 -0000 1.99
+++ lib/connect.c 6 May 2004 07:16:54 -0000
@@ -98,9 +98,7 @@
 #include "connect.h"
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 static bool verifyconnect(curl_socket_t sockfd);
 
Index: lib/content_encoding.c
===================================================================
RCS file: /repository/curl/lib/content_encoding.c,v
retrieving revision 1.14
diff -u -3 -H -r1.14 content_encoding.c
--- lib/content_encoding.c 26 Apr 2004 14:02:01 -0000 1.14
+++ lib/content_encoding.c 6 May 2004 07:16:55 -0000
@@ -32,6 +32,7 @@
 #include <curl/curl.h>
 #include "sendf.h"
 #include "content_encoding.h"
+#include "memdebug.h"
 
 #define DSIZ 0x10000 /* buffer size for decompressed data */
 
@@ -259,7 +260,7 @@
       followed in the first place, and it's even more unlikely for a transfer
       to fail immediately afterwards, it should seldom be a problem. */
       z->avail_in = nread;
- z->next_in = malloc(z->avail_in);
+ z->next_in = curl_malloc(z->avail_in);
       if (z->next_in == NULL) {
         return exit_zlib(z, &k->zlib_init, CURLE_OUT_OF_MEMORY);
       }
@@ -280,9 +281,9 @@
     unsigned char *oldblock = z->next_in;
 
     z->avail_in += nread;
- z->next_in = realloc(z->next_in, z->avail_in);
+ z->next_in = curl_realloc(z->next_in, z->avail_in);
     if (z->next_in == NULL) {
- free(oldblock);
+ curl_free(oldblock);
       return exit_zlib(z, &k->zlib_init, CURLE_OUT_OF_MEMORY);
     }
     /* Append the new block of data to the previous one */
@@ -291,7 +292,7 @@
     switch (check_gzip_header(z->next_in, z->avail_in, &hlen)) {
     case GZIP_OK:
       /* This is the zlib stream data */
- free(z->next_in);
+ curl_free(z->next_in);
       /* Don't point into the malloced block since we just freed it */
       z->next_in = (Bytef *)k->str + hlen + nread - z->avail_in;
       z->avail_in = z->avail_in - hlen;
@@ -304,7 +305,7 @@
 
     case GZIP_BAD:
     default:
- free(z->next_in);
+ curl_free(z->next_in);
       return exit_zlib(z, &k->zlib_init, process_zlib_error(data, z));
     }
 
Index: lib/cookie.c
===================================================================
RCS file: /repository/curl/lib/cookie.c,v
retrieving revision 1.52
diff -u -3 -H -r1.52 cookie.c
--- lib/cookie.c 10 Mar 2004 09:41:37 -0000 1.52
+++ lib/cookie.c 6 May 2004 07:16:56 -0000
@@ -94,23 +94,21 @@
 #include "sendf.h"
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 static void
 free_cookiemess(struct Cookie *co)
 {
   if(co->domain)
- free(co->domain);
+ curl_free(co->domain);
   if(co->path)
- free(co->path);
+ curl_free(co->path);
   if(co->name)
- free(co->name);
+ curl_free(co->name);
   if(co->value)
- free(co->value);
+ curl_free(co->value);
 
- free(co);
+ curl_free(co);
 }
 
 static bool tailmatch(const char *little, const char *bigone)
@@ -158,9 +156,10 @@
   bool badcookie = FALSE; /* cookies are good by default. mmmmm yummy */
 
   /* First, alloc and init a new struct for it */
- co = (struct Cookie *)calloc(sizeof(struct Cookie), 1);
+ co = (struct Cookie *)curl_malloc(sizeof(struct Cookie));
   if(!co)
     return NULL; /* bail out if we're this low on memory */
+ memset(co,0,sizeof(struct Cookie));
 
   if(httpheader) {
     /* This line was read off a HTTP-header */
@@ -202,7 +201,7 @@
           }
 
           if(strequal("path", name)) {
- co->path=strdup(whatptr);
+ co->path=curl_strdup(whatptr);
           }
           else if(strequal("domain", name)) {
             /* note that this name may or may not have a preceeding dot, but
@@ -259,7 +258,7 @@
                 const char *tailptr=whatptr;
                 if(tailptr[0] == '.')
                   tailptr++;
- co->domain=strdup(tailptr); /* don't prefix w/dots internally */
+ co->domain=curl_strdup(tailptr); /* don't prefix w/dots internally */
                 co->tailmatch=TRUE; /* we always do that if the domain name was
                                        given */
               }
@@ -274,7 +273,7 @@
             }
           }
           else if(strequal("version", name)) {
- co->version=strdup(whatptr);
+ co->version=curl_strdup(whatptr);
           }
           else if(strequal("max-age", name)) {
             /* Defined in RFC2109:
@@ -286,17 +285,17 @@
                cookie should be discarded immediately.
 
              */
- co->maxage = strdup(whatptr);
+ co->maxage = curl_strdup(whatptr);
             co->expires =
               atoi((*co->maxage=='\"')?&co->maxage[1]:&co->maxage[0]) + now;
           }
           else if(strequal("expires", name)) {
- co->expirestr=strdup(whatptr);
+ co->expirestr=curl_strdup(whatptr);
             co->expires = curl_getdate(what, &now);
           }
           else if(!co->name) {
- co->name = strdup(name);
- co->value = strdup(whatptr);
+ co->name = curl_strdup(name);
+ co->value = curl_strdup(whatptr);
           }
           /*
             else this is the second (or more) name we don't know
@@ -337,28 +336,28 @@
       /* we didn't get a cookie name or a bad one,
          this is an illegal line, bail out */
       if(co->expirestr)
- free(co->expirestr);
+ curl_free(co->expirestr);
       if(co->domain)
- free(co->domain);
+ curl_free(co->domain);
       if(co->path)
- free(co->path);
+ curl_free(co->path);
       if(co->name)
- free(co->name);
+ curl_free(co->name);
       if(co->value)
- free(co->value);
- free(co);
+ curl_free(co->value);
+ curl_free(co);
       return NULL;
     }
 
     if(NULL == co->domain)
       /* no domain was given in the header line, set the default now */
- co->domain=domain?strdup(domain):NULL;
+ co->domain=domain?curl_strdup(domain):NULL;
     if((NULL == co->path) && path) {
       /* no path was given in the header line, set the default now */
       char *endslash = strrchr(path, '/');
       if(endslash) {
         size_t pathlen = endslash-path+1; /* include the ending slash */
- co->path=malloc(pathlen+1); /* one extra for the zero byte */
+ co->path=curl_malloc(pathlen+1); /* one extra for the zero byte */
         if(co->path) {
           memcpy(co->path, path, pathlen);
           co->path[pathlen]=0; /* zero terminate */
@@ -375,7 +374,7 @@
 
     if(lineptr[0]=='#') {
       /* don't even try the comments */
- free(co);
+ curl_free(co);
       return NULL;
     }
     /* strip off the possible end-of-line characters */
@@ -390,7 +389,7 @@
 
     /* Here's a quick check to eliminate normal HTTP-headers from this */
     if(!firstptr || strchr(firstptr, ':')) {
- free(co);
+ curl_free(co);
       return NULL;
     }
 
@@ -402,7 +401,7 @@
       case 0:
         if(ptr[0]=='.') /* skip preceeding dots */
           ptr++;
- co->domain = strdup(ptr);
+ co->domain = curl_strdup(ptr);
         break;
       case 1:
         /* This field got its explanation on the 23rd of May 2001 by
@@ -423,11 +422,11 @@
            around it! Andrés García made us aware of this... */
         if (strcmp("TRUE", ptr) && strcmp("FALSE", ptr)) {
           /* only if the path doesn't look like a boolean option! */
- co->path = strdup(ptr);
+ co->path = curl_strdup(ptr);
           break;
         }
         /* this doesn't look like a path, make one up! */
- co->path = strdup("/");
+ co->path = curl_strdup("/");
         fields++; /* add a field and fall down to secure */
         /* FALLTHROUGH */
       case 3:
@@ -437,17 +436,17 @@
         co->expires = atoi(ptr);
         break;
       case 5:
- co->name = strdup(ptr);
+ co->name = curl_strdup(ptr);
         break;
       case 6:
- co->value = strdup(ptr);
+ co->value = curl_strdup(ptr);
         break;
       }
     }
 
     if(6 == fields) {
       /* we got a cookie with blank contents, fix it */
- co->value = strdup("");
+ co->value = curl_strdup("");
     }
     else if(7 != fields) {
       /* we did not find the sufficient number of fields to recognize this
@@ -509,15 +508,15 @@
 
         /* Free the newcomer and get out of here! */
         if(co->domain)
- free(co->domain);
+ curl_free(co->domain);
         if(co->path)
- free(co->path);
+ curl_free(co->path);
         if(co->name)
- free(co->name);
+ curl_free(co->name);
         if(co->value)
- free(co->value);
+ curl_free(co->value);
 
- free(co);
+ curl_free(co);
         return NULL;
       }
 
@@ -526,24 +525,24 @@
 
         /* then free all the old pointers */
         if(clist->name)
- free(clist->name);
+ curl_free(clist->name);
         if(clist->value)
- free(clist->value);
+ curl_free(clist->value);
         if(clist->domain)
- free(clist->domain);
+ curl_free(clist->domain);
         if(clist->path)
- free(clist->path);
+ curl_free(clist->path);
         if(clist->expirestr)
- free(clist->expirestr);
+ curl_free(clist->expirestr);
 
         if(clist->version)
- free(clist->version);
+ curl_free(clist->version);
         if(clist->maxage)
- free(clist->maxage);
+ curl_free(clist->maxage);
 
         *clist = *co; /* then store all the new data */
 
- free(co); /* free the newly alloced memory */
+ curl_free(co); /* free the newly alloced memory */
         co = clist; /* point to the previous struct instead */
 
         /* We have replaced a cookie, now skip the rest of the list but
@@ -599,11 +598,11 @@
   
   if(NULL == inc) {
     /* we didn't get a struct, create one */
- c = (struct CookieInfo *)malloc(sizeof(struct CookieInfo));
+ c = (struct CookieInfo *)curl_malloc(sizeof(struct CookieInfo));
     if(!c)
       return NULL; /* failed to get memory */
     memset(c, 0, sizeof(struct CookieInfo));
- c->filename = strdup(file?file:"none"); /* copy the name just in case */
+ c->filename = curl_strdup(file?file:"none"); /* copy the name just in case */
   }
   else {
     /* we got an already existing one, use that */
@@ -694,7 +693,7 @@
            /* and now, we know this is a match and we should create an
               entry for the return-linked-list */
            
- newco = (struct Cookie *)malloc(sizeof(struct Cookie));
+ newco = (struct Cookie *)curl_malloc(sizeof(struct Cookie));
            if(newco) {
              /* first, copy the whole source cookie: */
              memcpy(newco, co, sizeof(struct Cookie));
@@ -729,7 +728,7 @@
    if(co) {
       while(co) {
          next = co->next;
- free(co); /* we only free the struct since the "members" are all
+ curl_free(co); /* we only free the struct since the "members" are all
                       just copied! */
          co = next;
       }
@@ -749,31 +748,31 @@
    struct Cookie *next;
    if(c) {
       if(c->filename)
- free(c->filename);
+ curl_free(c->filename);
       co = c->cookies;
 
       while(co) {
          if(co->name)
- free(co->name);
+ curl_free(co->name);
          if(co->value)
- free(co->value);
+ curl_free(co->value);
          if(co->domain)
- free(co->domain);
+ curl_free(co->domain);
          if(co->path)
- free(co->path);
+ curl_free(co->path);
          if(co->expirestr)
- free(co->expirestr);
+ curl_free(co->expirestr);
 
          if(co->version)
- free(co->version);
+ curl_free(co->version);
          if(co->maxage)
- free(co->maxage);
+ curl_free(co->maxage);
 
          next = co->next;
- free(co);
+ curl_free(co);
          co = next;
       }
- free(c); /* free the base struct as well */
+ curl_free(c); /* free the base struct as well */
    }
 }
 
Index: lib/easy.c
===================================================================
RCS file: /repository/curl/lib/easy.c,v
retrieving revision 1.53
diff -u -3 -H -r1.53 easy.c
--- lib/easy.c 29 Apr 2004 10:58:22 -0000 1.53
+++ lib/easy.c 6 May 2004 07:16:57 -0000
@@ -81,9 +81,7 @@
 #include <curl/mprintf.h>
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
 /* win32_cleanup() is for win32 socket cleanup functionality, the opposite
@@ -366,7 +364,7 @@
   struct SessionHandle *data=(struct SessionHandle *)incurl;
 
   struct SessionHandle *outcurl = (struct SessionHandle *)
- malloc(sizeof(struct SessionHandle));
+ curl_malloc(sizeof(struct SessionHandle));
 
   if(NULL == outcurl)
     return NULL; /* failure */
@@ -377,7 +375,7 @@
 #ifdef USE_ARES
   /* If we use ares, we need to setup a new ares channel for the new handle */
   if(ARES_SUCCESS != ares_init(&outcurl->state.areschannel)) {
- free(outcurl);
+ curl_free(outcurl);
     return NULL;
   }
 #endif
@@ -387,9 +385,9 @@
    * get setup on-demand in the code, as that would probably decrease
    * the likeliness of us forgetting to init a buffer here in the future.
    */
- outcurl->state.headerbuff=(char*)malloc(HEADERSIZE);
+ outcurl->state.headerbuff=(char*)curl_malloc(HEADERSIZE);
   if(!outcurl->state.headerbuff) {
- free(outcurl); /* free the memory again */
+ curl_free(outcurl); /* free the memory again */
     return NULL;
   }
   outcurl->state.headersize=HEADERSIZE;
@@ -398,11 +396,11 @@
   outcurl->set = data->set;
   outcurl->state.numconnects = data->state.numconnects;
   outcurl->state.connects = (struct connectdata **)
- malloc(sizeof(struct connectdata *) * outcurl->state.numconnects);
+ curl_malloc(sizeof(struct connectdata *) * outcurl->state.numconnects);
 
   if(!outcurl->state.connects) {
- free(outcurl->state.headerbuff);
- free(outcurl);
+ curl_free(outcurl->state.headerbuff);
+ curl_free(outcurl);
     return NULL;
   }
   memset(outcurl->state.connects, 0,
@@ -421,15 +419,15 @@
 
   /* duplicate all values in 'change' */
   if(data->change.url) {
- outcurl->change.url = strdup(data->change.url);
+ outcurl->change.url = curl_strdup(data->change.url);
     outcurl->change.url_alloc = TRUE;
   }
   if(data->change.proxy) {
- outcurl->change.proxy = strdup(data->change.proxy);
+ outcurl->change.proxy = curl_strdup(data->change.proxy);
     outcurl->change.proxy_alloc = TRUE;
   }
   if(data->change.referer) {
- outcurl->change.referer = strdup(data->change.referer);
+ outcurl->change.referer = curl_strdup(data->change.referer);
     outcurl->change.referer_alloc = TRUE;
   }
 
Index: lib/escape.c
===================================================================
RCS file: /repository/curl/lib/escape.c,v
retrieving revision 1.30
diff -u -3 -H -r1.30 escape.c
--- lib/escape.c 8 Mar 2004 08:38:29 -0000 1.30
+++ lib/escape.c 6 May 2004 07:16:57 -0000
@@ -33,14 +33,12 @@
 #include <string.h>
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 char *curl_escape(const char *string, int length)
 {
   size_t alloc = (length?(size_t)length:strlen(string))+1;
- char *ns = malloc(alloc);
+ char *ns = curl_malloc(alloc);
   char *testing_ptr = NULL;
   unsigned char in;
   size_t newlen = alloc;
@@ -56,9 +54,9 @@
       newlen += 2; /* the size grows with two, since this'll become a %XX */
       if(newlen > alloc) {
         alloc *= 2;
- testing_ptr = realloc(ns, alloc);
+ testing_ptr = curl_realloc(ns, alloc);
         if(!testing_ptr) {
- free( ns );
+ curl_free( ns );
           return NULL;
         }
         else {
@@ -86,7 +84,7 @@
 char *curl_unescape(const char *string, int length)
 {
   int alloc = (length?length:(int)strlen(string))+1;
- char *ns = malloc(alloc);
+ char *ns = curl_malloc(alloc);
   unsigned char in;
   int strindex=0;
   long hex;
@@ -118,11 +116,3 @@
   ns[strindex]=0; /* terminate it */
   return ns;
 }
-
-/* For operating systems/environments that use different malloc/free
- ssystems for the app and for this library, we provide a free that uses
- the library's memory system */
-void curl_free(void *p)
-{
- free(p);
-}
Index: lib/file.c
===================================================================
RCS file: /repository/curl/lib/file.c,v
retrieving revision 1.54
diff -u -3 -H -r1.54 file.c
--- lib/file.c 26 Apr 2004 07:11:39 -0000 1.54
+++ lib/file.c 6 May 2004 07:17:00 -0000
@@ -90,9 +90,7 @@
 #include <curl/mprintf.h>
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /*
  * Curl_file_connect() gets called from Curl_protocol_connect() to allow us to
@@ -109,9 +107,10 @@
   char *actual_path;
 #endif
 
- file = (struct FILEPROTO *)calloc(sizeof(struct FILEPROTO), 1);
+ file = (struct FILEPROTO *)curl_malloc(sizeof(struct FILEPROTO));
   if(!file)
     return CURLE_OUT_OF_MEMORY;
+ memset(file,0,sizeof(struct FILEPROTO));
 
   conn->proto.file = file;
 
@@ -148,7 +147,7 @@
 #else
   fd = open(real_path, O_RDONLY);
 #endif
- free(real_path);
+ curl_free(real_path);
 
   if(fd == -1) {
     failf(conn->data, "Couldn't open file %s", conn->path);
Index: lib/formdata.c
===================================================================
RCS file: /repository/curl/lib/formdata.c,v
retrieving revision 1.60
diff -u -3 -H -r1.60 formdata.c
--- lib/formdata.c 4 May 2004 09:31:04 -0000 1.60
+++ lib/formdata.c 6 May 2004 07:17:00 -0000
@@ -116,9 +116,7 @@
 #include "strequal.h"
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /* Length of the random boundary string. */
 #define BOUNDARY_LENGTH 40
@@ -153,7 +151,7 @@
             struct curl_httppost **last_post)
 {
   struct curl_httppost *post;
- post = (struct curl_httppost *)malloc(sizeof(struct curl_httppost));
+ post = (struct curl_httppost *)curl_malloc(sizeof(struct curl_httppost));
   if(post) {
     memset(post, 0, sizeof(struct curl_httppost));
     post->name = name;
@@ -204,7 +202,7 @@
                               FormInfo *parent_form_info)
 {
   FormInfo *form_info;
- form_info = (FormInfo *)malloc(sizeof(FormInfo));
+ form_info = (FormInfo *)curl_malloc(sizeof(FormInfo));
   if(form_info) {
     memset(form_info, 0, sizeof(FormInfo));
     if (value)
@@ -304,7 +302,7 @@
     length = strlen(*buffer);
     add = TRUE;
   }
- *buffer = (char*)malloc(length+add);
+ *buffer = (char*)curl_malloc(length+add);
   if (!*buffer)
     return 1;
   memcpy(*buffer, src, length);
@@ -384,7 +382,7 @@
   /*
    * We need to allocate the first struct to fill in.
    */
- first_form = (FormInfo *)malloc(sizeof(struct FormInfo));
+ first_form = (FormInfo *)curl_malloc(sizeof(struct FormInfo));
   if(first_form) {
     memset(first_form, 0, sizeof(FormInfo));
     current_form = first_form;
@@ -493,7 +491,7 @@
         char *filename = array_state?
           array_value:va_arg(params, char *);
         if (filename) {
- current_form->value = strdup(filename);
+ current_form->value = curl_strdup(filename);
           current_form->flags |= HTTPPOST_READFILE;
         }
         else
@@ -510,7 +508,7 @@
         if (current_form->value) {
           if (current_form->flags & HTTPPOST_FILENAME) {
             if (filename) {
- if (!(current_form = AddFormInfo(strdup(filename),
+ if (!(current_form = AddFormInfo(curl_strdup(filename),
                                                NULL, current_form)))
                 return_value = CURL_FORMADD_MEMORY;
             }
@@ -522,7 +520,7 @@
         }
         else {
           if (filename)
- current_form->value = strdup(filename);
+ current_form->value = curl_strdup(filename);
           else
             return_value = CURL_FORMADD_NULL;
           current_form->flags |= HTTPPOST_FILENAME;
@@ -538,7 +536,7 @@
         if (current_form->value) {
           if (current_form->flags & HTTPPOST_BUFFER) {
             if (filename) {
- if (!(current_form = AddFormInfo(strdup(filename),
+ if (!(current_form = AddFormInfo(curl_strdup(filename),
                                                NULL, current_form)))
                 return_value = CURL_FORMADD_MEMORY;
             }
@@ -550,7 +548,7 @@
         }
         else {
           if (filename)
- current_form->value = strdup(filename);
+ current_form->value = curl_strdup(filename);
           else
             return_value = CURL_FORMADD_NULL;
           current_form->flags |= HTTPPOST_BUFFER;
@@ -588,7 +586,7 @@
           if (current_form->flags & HTTPPOST_FILENAME) {
             if (contenttype) {
               if (!(current_form = AddFormInfo(NULL,
- strdup(contenttype),
+ curl_strdup(contenttype),
                                                current_form)))
                 return_value = CURL_FORMADD_MEMORY;
             }
@@ -600,7 +598,7 @@
         }
         else {
           if (contenttype)
- current_form->contenttype = strdup(contenttype);
+ current_form->contenttype = curl_strdup(contenttype);
           else
             return_value = CURL_FORMADD_NULL;
         }
@@ -628,7 +626,7 @@
         if( current_form->showfilename )
           return_value = CURL_FORMADD_OPTION_TWICE;
         else
- current_form->showfilename = strdup(filename);
+ current_form->showfilename = curl_strdup(filename);
         break;
       }
     default:
@@ -666,7 +664,7 @@
              !form->contenttype ) {
           /* our contenttype is missing */
           form->contenttype
- = strdup(ContentTypeForFilename(form->value, prevtype));
+ = curl_strdup(ContentTypeForFilename(form->value, prevtype));
         }
         if ( !(form->flags & HTTPPOST_PTRNAME) &&
              (form == first_form) ) {
@@ -711,7 +709,7 @@
     
     delete_form = form;
     form = form->more;
- free (delete_form);
+ curl_free (delete_form);
   }
 
   return return_value;
@@ -741,14 +739,14 @@
                           size_t length)
 {
   struct FormData *newform = (struct FormData *)
- malloc(sizeof(struct FormData));
+ curl_malloc(sizeof(struct FormData));
   newform->next = NULL;
 
   /* we make it easier for plain strings: */
   if(!length)
     length = strlen((char *)line);
 
- newform->line = (char *)malloc(length+1);
+ newform->line = (char *)curl_malloc(length+1);
   memcpy(newform->line, line, length);
   newform->length = length;
   newform->line[length]=0; /* zero terminate for easier debugging */
@@ -792,7 +790,7 @@
 
   static char table16[]="abcdef0123456789";
 
- retstring = (char *)malloc(BOUNDARY_LENGTH+1);
+ retstring = (char *)curl_malloc(BOUNDARY_LENGTH+1);
 
   if(!retstring)
     return NULL; /* failed */
@@ -821,8 +819,8 @@
 
   do {
     next=form->next; /* the following form line */
- free(form->line); /* free the line */
- free(form); /* free the struct */
+ curl_free(form->line); /* free the line */
+ curl_free(form); /* free the struct */
   
   } while((form=next)); /* continue */
 }
@@ -847,14 +845,14 @@
       curl_formfree(form->more);
 
     if( !(form->flags & HTTPPOST_PTRNAME) && form->name)
- free(form->name); /* free the name */
+ curl_free(form->name); /* free the name */
     if( !(form->flags & HTTPPOST_PTRCONTENTS) && form->contents)
- free(form->contents); /* free the contents */
+ curl_free(form->contents); /* free the contents */
     if(form->contenttype)
- free(form->contenttype); /* free the content type */
+ curl_free(form->contenttype); /* free the content type */
     if(form->showfilename)
- free(form->showfilename); /* free the faked file name */
- free(form); /* free the struct */
+ curl_free(form->showfilename); /* free the faked file name */
+ curl_free(form); /* free the struct */
 
   } while((form=next)); /* continue */
 }
@@ -1003,7 +1001,7 @@
         }
         else {
           Curl_formclean(firstform);
- free(boundary);
+ curl_free(boundary);
           *finalform = NULL;
           return CURLE_READ_ERROR;
         }
@@ -1026,7 +1024,7 @@
       size += AddFormDataf(&form,
                            "\r\n--%s--",
                            fileboundary);
- free(fileboundary);
+ curl_free(fileboundary);
     }
 
   } while((post=post->next)); /* for each field */
@@ -1038,7 +1036,7 @@
 
   *sizep = size;
 
- free(boundary);
+ curl_free(boundary);
 
   *finalform=firstform;
 
Index: lib/ftp.c
===================================================================
RCS file: /repository/curl/lib/ftp.c,v
retrieving revision 1.253
diff -u -3 -H -r1.253 ftp.c
--- lib/ftp.c 27 Apr 2004 13:56:23 -0000 1.253
+++ lib/ftp.c 6 May 2004 07:17:04 -0000
@@ -101,9 +101,7 @@
 #include <curl/mprintf.h>
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 #ifdef HAVE_NI_WITHSCOPEID
 #define NIFLAGS NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID
@@ -128,15 +126,15 @@
   if(ftp->dirs) {
     for (i=0; i < ftp->dirdepth; i++){
       if(ftp->dirs[i]) {
- free(ftp->dirs[i]);
+ curl_free(ftp->dirs[i]);
         ftp->dirs[i]=NULL;
       }
     }
- free(ftp->dirs);
+ curl_free(ftp->dirs);
     ftp->dirs = NULL;
   }
   if(ftp->file) {
- free(ftp->file);
+ curl_free(ftp->file);
     ftp->file = NULL;
   }
 }
@@ -330,7 +328,7 @@
          */
         memcpy(ptr, ftp->cache, (int)ftp->cache_size);
         gotbytes = (int)ftp->cache_size;
- free(ftp->cache); /* free the cache */
+ curl_free(ftp->cache); /* free the cache */
         ftp->cache = NULL; /* clear the pointer */
         ftp->cache_size = 0; /* zero the size just in case */
       }
@@ -409,7 +407,7 @@
              already! Cleverly figured out by Eric Lavigne in December
              2001. */
           ftp->cache_size = gotbytes - i;
- ftp->cache = (char *)malloc((int)ftp->cache_size);
+ ftp->cache = (char *)curl_malloc((int)ftp->cache_size);
           if(ftp->cache)
             memcpy(ftp->cache, line_start, (int)ftp->cache_size);
           else
@@ -468,7 +466,7 @@
   CURLcode result;
   int ftpcode, try;
 
- ftp = (struct FTP *)malloc(sizeof(struct FTP));
+ ftp = (struct FTP *)curl_malloc(sizeof(struct FTP));
   if(!ftp)
     return CURLE_OUT_OF_MEMORY;
 
@@ -677,7 +675,7 @@
     return result;
 
   if(ftpcode == 257) {
- char *dir = (char *)malloc(nread+1);
+ char *dir = (char *)curl_malloc(nread+1);
     char *store=dir;
     char *ptr=&buf[4]; /* start on the first letter */
 
@@ -716,7 +714,7 @@
     }
     else {
       /* couldn't get the path */
- free(dir);
+ curl_free(dir);
       infof(data, "Failed to figure out path\n");
     }
 
@@ -2343,7 +2341,7 @@
 
   ftp->dirdepth = 0;
   ftp->diralloc = 5; /* default dir depth to allocate */
- ftp->dirs = (char **)malloc(ftp->diralloc * sizeof(ftp->dirs[0]));
+ ftp->dirs = (char **)curl_malloc(ftp->diralloc * sizeof(ftp->dirs[0]));
   if(!ftp->dirs)
     return CURLE_OUT_OF_MEMORY;
   ftp->dirs[0] = NULL; /* to start with */
@@ -2379,7 +2377,7 @@
         /* enlarge array */
         char *bigger;
         ftp->diralloc *= 2; /* double the size each time */
- bigger = realloc(ftp->dirs, ftp->diralloc * sizeof(ftp->dirs[0]));
+ bigger = curl_realloc(ftp->dirs, ftp->diralloc * sizeof(ftp->dirs[0]));
         if(!bigger) {
           freedirs(ftp);
           return CURLE_OUT_OF_MEMORY;
@@ -2528,9 +2526,9 @@
     (void)ftp_quit(conn); /* ignore errors on the QUIT */
 
     if(ftp->entrypath)
- free(ftp->entrypath);
+ curl_free(ftp->entrypath);
     if(ftp->cache) {
- free(ftp->cache);
+ curl_free(ftp->cache);
       ftp->cache = NULL;
     }
     freedirs(ftp);
Index: lib/getenv.c
===================================================================
RCS file: /repository/curl/lib/getenv.c,v
retrieving revision 1.23
diff -u -3 -H -r1.23 getenv.c
--- lib/getenv.c 29 Jan 2004 13:56:45 -0000 1.23
+++ lib/getenv.c 6 May 2004 07:17:08 -0000
@@ -37,9 +37,7 @@
 
 #include <curl/curl.h>
 
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 static
 char *GetEnv(const char *variable)
@@ -62,7 +60,7 @@
   char *env = getenv(variable);
 #endif
 #endif
- return (env && env[0])?strdup(env):NULL;
+ return (env && env[0])?curl_strdup(env):NULL;
 }
 
 char *curl_getenv(const char *v)
Index: lib/getinfo.c
===================================================================
RCS file: /repository/curl/lib/getinfo.c,v
retrieving revision 1.36
diff -u -3 -H -r1.36 getinfo.c
--- lib/getinfo.c 11 Mar 2004 21:51:55 -0000 1.36
+++ lib/getinfo.c 6 May 2004 07:17:08 -0000
@@ -37,11 +37,7 @@
 #endif
 
 /* Make this the last #include */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#else
-#include <stdlib.h>
-#endif
 
 /*
  * This is supposed to be called in the beginning of a permform() session
@@ -64,7 +60,7 @@
   info->filetime=-1; /* -1 is an illegal time and thus means unknown */
   
   if (info->contenttype)
- free(info->contenttype);
+ curl_free(info->contenttype);
   info->contenttype = NULL;
 
   info->header_size = 0;
Index: lib/hash.c
===================================================================
RCS file: /repository/curl/lib/hash.c,v
retrieving revision 1.21
diff -u -3 -H -r1.21 hash.c
--- lib/hash.c 4 May 2004 13:40:30 -0000 1.21
+++ lib/hash.c 6 May 2004 07:17:08 -0000
@@ -29,10 +29,8 @@
 #include "hash.h"
 #include "llist.h"
 
-#ifdef CURLDEBUG
 /* this must be the last include file */
 #include "memdebug.h"
-#endif
 
 
 static unsigned long
@@ -56,12 +54,12 @@
   curl_hash_element *e = (curl_hash_element *) element;
 
   if (e->key) {
- free(e->key);
+ curl_free(e->key);
   }
 
   h->dtor(e->ptr);
 
- free(e);
+ curl_free(e);
 }
 
 /* return 1 on error, 0 is fine */
@@ -74,14 +72,14 @@
   h->size = 0;
   h->slots = slots;
 
- h->table = (curl_llist **) malloc(slots * sizeof(curl_llist *));
+ h->table = (curl_llist **) curl_malloc(slots * sizeof(curl_llist *));
   if(h->table) {
     for (i = 0; i < slots; ++i) {
       h->table[i] = Curl_llist_alloc((curl_llist_dtor) hash_element_dtor);
       if(!h->table[i]) {
         while(i--)
           Curl_llist_destroy(h->table[i], NULL);
- free(h->table);
+ curl_free(h->table);
         return 1; /* failure */
       }
     }
@@ -96,11 +94,11 @@
 {
   curl_hash *h;
 
- h = (curl_hash *) malloc(sizeof(curl_hash));
+ h = (curl_hash *) curl_malloc(sizeof(curl_hash));
   if (h) {
     if(Curl_hash_init(h, slots, dtor)) {
       /* failure */
- free(h);
+ curl_free(h);
       h = NULL;
     }
   }
@@ -124,10 +122,10 @@
 mk_hash_element(char *key, size_t key_len, const void *p)
 {
   curl_hash_element *he =
- (curl_hash_element *) malloc(sizeof(curl_hash_element));
+ (curl_hash_element *) curl_malloc(sizeof(curl_hash_element));
 
   if(he) {
- he->key = strdup(key);
+ he->key = curl_strdup(key);
     he->key_len = key_len;
     he->ptr = (void *) p;
   }
@@ -238,7 +236,7 @@
     Curl_llist_destroy(h->table[i], (void *) h);
   }
 
- free(h->table);
+ curl_free(h->table);
 }
 
 void
@@ -281,6 +279,6 @@
     return;
 
   Curl_hash_clean(h);
- free(h);
+ curl_free(h);
 }
 
Index: lib/hostares.c
===================================================================
RCS file: /repository/curl/lib/hostares.c,v
retrieving revision 1.3
diff -u -3 -H -r1.3 hostares.c
--- lib/hostares.c 27 Apr 2004 13:56:23 -0000 1.3
+++ lib/hostares.c 6 May 2004 07:17:09 -0000
@@ -88,9 +88,7 @@
 #endif
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /***********************************************************************
  * Only for ares-enabled builds
@@ -275,7 +273,7 @@
     /* This is a dotted IP address 123.123.123.123-style */
     return Curl_ip2addr(in, hostname);
 
- bufp = strdup(hostname);
+ bufp = curl_strdup(hostname);
 
   if(bufp) {
     Curl_safefree(conn->async.hostname);
Index: lib/hostasyn.c
===================================================================
RCS file: /repository/curl/lib/hostasyn.c,v
retrieving revision 1.1
diff -u -3 -H -r1.1 hostasyn.c
--- lib/hostasyn.c 26 Apr 2004 07:20:11 -0000 1.1
+++ lib/hostasyn.c 6 May 2004 07:17:09 -0000
@@ -88,9 +88,7 @@
 #endif
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /***********************************************************************
  * Only for builds using asynchronous name resolves
Index: lib/hostip.c
===================================================================
RCS file: /repository/curl/lib/hostip.c,v
retrieving revision 1.150
diff -u -3 -H -r1.150 hostip.c
--- lib/hostip.c 4 May 2004 13:40:30 -0000 1.150
+++ lib/hostip.c 6 May 2004 07:17:10 -0000
@@ -88,9 +88,7 @@
 #endif
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /*
  * hostip.c explained
@@ -207,7 +205,7 @@
     _num_chars(port); /* number of characters the port will take up */
   
   /* Allocate the new entry id */
- id = malloc(*entry_len + 1); /* 1 extra for the zero terminator */
+ id = curl_malloc(*entry_len + 1); /* 1 extra for the zero terminator */
   if (!id)
     return NULL;
 
@@ -324,9 +322,9 @@
     return NULL;
 
   /* Create a new cache entry */
- dns = (struct Curl_dns_entry *) malloc(sizeof(struct Curl_dns_entry));
+ dns = (struct Curl_dns_entry *) curl_malloc(sizeof(struct Curl_dns_entry));
   if (!dns) {
- free(entry_id);
+ curl_free(entry_id);
     return NULL;
   }
 
@@ -339,8 +337,8 @@
   dns2 = Curl_hash_add(data->hostcache, entry_id, entry_len+1, (void *)dns);
   if(!dns2) {
     /* Major badness, run away. */
- free(dns);
- free(entry_id);
+ curl_free(dns);
+ curl_free(entry_id);
     return NULL;
   }
   time(&now);
@@ -350,7 +348,7 @@
   dns->inuse++; /* mark entry as in-use */
 
   /* free the allocated entry_id again */
- free(entry_id);
+ curl_free(entry_id);
 
   return dns;
 }
@@ -414,7 +412,7 @@
     Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
 
   /* free the allocated entry_id again */
- free(entry_id);
+ curl_free(entry_id);
 
   if (!dns) {
     /* The entry was not in the cache. Resolve it to IP address */
@@ -499,7 +497,7 @@
 
   Curl_freeaddrinfo(p->addr);
 
- free(p);
+ curl_free(p);
 }
 
 /*
@@ -556,7 +554,7 @@
   int i;
   char *str;
   size_t len;
- char *aptr = (char *)malloc(CURL_HOSTENT_SIZE);
+ char *aptr = (char *)curl_malloc(CURL_HOSTENT_SIZE);
   char *bufptr = aptr;
 
   if(!bufptr)
@@ -622,7 +620,7 @@
 
   /* now, shrink the allocated buffer to the size we actually need, which
      most often is only a fraction of the original alloc */
- newbuf=(char *)realloc(aptr, (long)(bufptr-aptr));
+ newbuf=(char *)curl_realloc(aptr, (long)(bufptr-aptr));
 
   /* if the alloc moved, we need to adjust the hostent struct */
   if(newbuf != aptr)
Index: lib/hostip4.c
===================================================================
RCS file: /repository/curl/lib/hostip4.c,v
retrieving revision 1.2
diff -u -3 -H -r1.2 hostip4.c
--- lib/hostip4.c 26 Apr 2004 12:02:33 -0000 1.2
+++ lib/hostip4.c 6 May 2004 07:17:11 -0000
@@ -88,9 +88,7 @@
 #endif
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /***********************************************************************
  * Only for plain-ipv4 builds
@@ -104,7 +102,7 @@
  */
 void Curl_freeaddrinfo(Curl_addrinfo *p)
 {
- free(p); /* works fine for the ARES case too */
+ curl_free(p); /* works fine for the ARES case too */
 }
 
 /*
@@ -138,7 +136,7 @@
     char *h_addr_list[2];
     struct in_addr addrentry;
     char h_name[16]; /* 123.123.123.123 = 15 letters is maximum */
- } *buf = (struct namebuf *)malloc(sizeof(struct namebuf));
+ } *buf = (struct namebuf *)curl_malloc(sizeof(struct namebuf));
 
   if(!buf)
     return NULL; /* major failure */
@@ -206,9 +204,11 @@
     int h_errnop;
     int res=ERANGE;
     int step_size=200;
- int *buf = (int *)calloc(CURL_HOSTENT_SIZE, 1);
+ int *buf = (int *)curl_malloc(CURL_HOSTENT_SIZE);
     if(!buf)
       return NULL; /* major failure */
+ memset(buf,0,CURL_HOSTENT_SIZE);
+
     /*
      * The clearing of the buffer is a workaround for a gethostbyname_r bug in
      * qnx nto and it is also _required_ for some of these functions on some
@@ -243,7 +243,7 @@
 
     if(h) {
       int offset;
- h=(struct hostent *)realloc(buf, step_size);
+ h=(struct hostent *)curl_realloc(buf, step_size);
       offset=(long)h-(long)buf;
       Curl_hostent_relocate(h, offset);
       buf=(int *)h;
@@ -305,7 +305,7 @@
 #endif
     if(!res) {
       int offset;
- h=(struct hostent *)realloc(buf, step_size);
+ h=(struct hostent *)curl_realloc(buf, step_size);
       offset=(long)h-(long)buf;
       Curl_hostent_relocate(h, offset);
       buf=(int *)h;
@@ -368,7 +368,7 @@
       {
       infof(data, "gethostbyname_r(2) failed for %s\n", hostname);
       h = NULL; /* set return code to NULL */
- free(buf);
+ curl_free(buf);
     }
 #else /* HAVE_GETHOSTBYNAME_R */
     /*
Index: lib/hostip6.c
===================================================================
RCS file: /repository/curl/lib/hostip6.c,v
retrieving revision 1.3
diff -u -3 -H -r1.3 hostip6.c
--- lib/hostip6.c 26 Apr 2004 15:11:56 -0000 1.3
+++ lib/hostip6.c 6 May 2004 07:17:11 -0000
@@ -89,9 +89,7 @@
 #endif
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /***********************************************************************
  * Only for ipv6-enabled builds
Index: lib/hostsyn.c
===================================================================
RCS file: /repository/curl/lib/hostsyn.c,v
retrieving revision 1.1
diff -u -3 -H -r1.1 hostsyn.c
--- lib/hostsyn.c 26 Apr 2004 07:20:11 -0000 1.1
+++ lib/hostsyn.c 6 May 2004 07:17:11 -0000
@@ -88,9 +88,7 @@
 #endif
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /***********************************************************************
  * Only for builds using synchronous name resolves
Index: lib/hostthre.c
===================================================================
RCS file: /repository/curl/lib/hostthre.c,v
retrieving revision 1.5
diff -u -3 -H -r1.5 hostthre.c
--- lib/hostthre.c 27 Apr 2004 15:13:46 -0000 1.5
+++ lib/hostthre.c 6 May 2004 07:17:12 -0000
@@ -86,9 +86,7 @@
 #include "inet_ntop.h"
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /***********************************************************************
  * Only for Windows threaded name resolves builds
@@ -246,14 +244,14 @@
 static void destroy_thread_data (struct Curl_async *async)
 {
   if (async->hostname)
- free(async->hostname);
+ curl_free(async->hostname);
 
   if (async->os_specific) {
     curl_socket_t sock = ((const struct thread_data*)async->os_specific)->dummy_sock;
 
     if (sock != CURL_SOCKET_BAD)
       sclose(sock);
- free(async->os_specific);
+ curl_free(async->os_specific);
   }
   async->hostname = NULL;
   async->os_specific = NULL;
@@ -269,17 +267,18 @@
                                  const char *hostname, int port,
                                  const Curl_addrinfo *hints)
 {
- struct thread_data *td = calloc(sizeof(*td), 1);
+ struct thread_data *td = curl_malloc(sizeof(*td));
 
   if (!td) {
     SetLastError(ENOMEM);
     return FALSE;
   }
+ memset(td,0,sizeof(*td));
 
   Curl_safefree(conn->async.hostname);
- conn->async.hostname = strdup(hostname);
+ conn->async.hostname = curl_strdup(hostname);
   if (!conn->async.hostname) {
- free(td);
+ curl_free(td);
     SetLastError(ENOMEM);
     return FALSE;
   }
Index: lib/http.c
===================================================================
RCS file: /repository/curl/lib/http.c,v
retrieving revision 1.222
diff -u -3 -H -r1.222 http.c
--- lib/http.c 5 May 2004 13:00:03 -0000 1.222
+++ lib/http.c 6 May 2004 07:17:15 -0000
@@ -99,9 +99,7 @@
 #include <curl/mprintf.h>
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /*
  * checkheaders() checks the linked list of custom HTTP headers for a
@@ -151,11 +149,11 @@
                         strlen(data->state.buffer),
                         &authorization) > 0) {
     if(*userp)
- free(*userp);
+ curl_free(*userp);
     *userp = aprintf( "%sAuthorization: Basic %s\015\012",
                       proxy?"Proxy-":"",
                       authorization);
- free(authorization);
+ curl_free(authorization);
   }
   else
     return CURLE_OUT_OF_MEMORY;
@@ -226,7 +224,7 @@
   }
      
   if(pickhost || pickproxy)
- conn->newurl = strdup(data->change.url); /* clone URL */
+ conn->newurl = curl_strdup(data->change.url); /* clone URL */
 
   else if((data->info.httpcode < 400) &&
           (!data->state.authhost.done)) {
@@ -236,7 +234,7 @@
        we didn't try HEAD or GET */
     if((data->set.httpreq != HTTPREQ_GET) &&
        (data->set.httpreq != HTTPREQ_HEAD)) {
- conn->newurl = strdup(data->change.url); /* clone URL */
+ conn->newurl = curl_strdup(data->change.url); /* clone URL */
       data->state.authhost.done = TRUE;
     }
   }
@@ -455,7 +453,7 @@
       /* if exactly this is wanted, go */
       int neg = Curl_input_negotiate(conn, start);
       if (neg == 0) {
- conn->newurl = strdup(data->change.url);
+ conn->newurl = curl_strdup(data->change.url);
         data->state.authproblem = (conn->newurl == NULL);
       }
       else {
@@ -678,7 +676,7 @@
 send_buffer *add_buffer_init(void)
 {
   send_buffer *blonk;
- blonk=(send_buffer *)malloc(sizeof(send_buffer));
+ blonk=(send_buffer *)curl_malloc(sizeof(send_buffer));
   if(blonk) {
     memset(blonk, 0, sizeof(send_buffer));
     return blonk;
@@ -772,8 +770,8 @@
     /* the full buffer was sent, clean up and return */
   }
   if(in->buffer)
- free(in->buffer);
- free(in);
+ curl_free(in->buffer);
+ curl_free(in);
 
   return res;
 }
@@ -793,14 +791,14 @@
 
   if(s) {
     CURLcode result = add_buffer(in, s, strlen(s));
- free(s);
+ curl_free(s);
     if(CURLE_OK == result)
       return CURLE_OK;
   }
   /* If we failed, we cleanup the whole buffer and return error */
   if(in->buffer)
- free(in->buffer);
- free(in);
+ curl_free(in->buffer);
+ curl_free(in);
   return CURLE_OUT_OF_MEMORY;
 }
 
@@ -818,10 +816,10 @@
     new_size = (in->size_used+size)*2;
     if(in->buffer)
       /* we have a buffer, enlarge the existing one */
- new_rb = (char *)realloc(in->buffer, new_size);
+ new_rb = (char *)curl_realloc(in->buffer, new_size);
     else
       /* create a new buffer */
- new_rb = (char *)malloc(new_size);
+ new_rb = (char *)curl_malloc(new_size);
 
     if(!new_rb)
       return CURLE_OUT_OF_MEMORY;
@@ -936,7 +934,7 @@
       /* This only happens if we've looped here due to authentication reasons,
          and we don't really use the newly cloned URL here then. Just free()
          it. */
- free(conn->newurl);
+ curl_free(conn->newurl);
       conn->newurl = NULL;
     }
 
@@ -963,7 +961,7 @@
       if(result)
         failf(data, "Failed sending CONNECT to proxy");
     }
- free(host_port);
+ curl_free(host_port);
     if(result)
       return result;
 
@@ -1161,9 +1159,9 @@
        original host name */
     if (data->state.auth_host)
       /* Free to avoid leaking memory on multiple requests*/
- free(data->state.auth_host);
+ curl_free(data->state.auth_host);
 
- data->state.auth_host = strdup(conn->host.name);
+ data->state.auth_host = curl_strdup(conn->host.name);
   }
 
   return CURLE_OK;
@@ -1192,8 +1190,8 @@
   if(http->send_buffer) {
     send_buffer *buff = http->send_buffer;
     
- free(buff->buffer);
- free(buff);
+ curl_free(buff->buffer);
+ curl_free(buff);
     http->send_buffer = NULL; /* cleaer the pointer */
   }
 
@@ -1241,7 +1239,7 @@
   if(!conn->proto.http) {
     /* Only allocate this struct if we don't already have it! */
 
- http = (struct HTTP *)malloc(sizeof(struct HTTP));
+ http = (struct HTTP *)curl_malloc(sizeof(struct HTTP));
     if(!http)
       return CURLE_OUT_OF_MEMORY;
     memset(http, 0, sizeof(struct HTTP));
@@ -1291,7 +1289,7 @@
      with the user-agent string specified, we erase the previously made string
      here. */
   if(checkheaders(data, "User-Agent:") && conn->allocptr.uagent) {
- free(conn->allocptr.uagent);
+ curl_free(conn->allocptr.uagent);
     conn->allocptr.uagent=NULL;
   }
 
@@ -1366,7 +1364,7 @@
     
     if(ptr != start) {
       size_t len=ptr-start;
- conn->allocptr.cookiehost = malloc(len+1);
+ conn->allocptr.cookiehost = curl_malloc(len+1);
       if(!conn->allocptr.cookiehost)
         return CURLE_OUT_OF_MEMORY;
       memcpy(conn->allocptr.cookiehost, start, len);
@@ -1429,7 +1427,7 @@
         
         char *newurl;
         
- newurl = malloc(urllen + newlen - currlen + 1);
+ newurl = curl_malloc(urllen + newlen - currlen + 1);
         if(newurl) {
           /* copy the part before the host name */
           memcpy(newurl, url, ptr - url);
@@ -1440,7 +1438,7 @@
                  ptr + currlen, /* copy the trailing zero byte too */
                  urllen - (ptr-url) - currlen + 1);
           if(data->change.url_alloc)
- free(data->change.url);
+ curl_free(data->change.url);
           data->change.url = newurl;
           data->change.url_alloc = TRUE;
         }
@@ -1538,7 +1536,7 @@
        !checkheaders(data, "Range:")) {
       /* if a line like this was already allocated, free the previous one */
       if(conn->allocptr.rangeline)
- free(conn->allocptr.rangeline);
+ curl_free(conn->allocptr.rangeline);
       conn->allocptr.rangeline = aprintf("Range: bytes=%s\r\n", conn->range);
     }
     else if((httpreq != HTTPREQ_GET) &&
Index: lib/http_chunks.c
===================================================================
RCS file: /repository/curl/lib/http_chunks.c,v
retrieving revision 1.23
diff -u -3 -H -r1.23 http_chunks.c
--- lib/http_chunks.c 4 Mar 2004 15:25:06 -0000 1.23
+++ lib/http_chunks.c 6 May 2004 07:17:15 -0000
@@ -40,9 +40,7 @@
 #include <curl/mprintf.h>
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /*
  * Chunk format (simplified):
Index: lib/http_digest.c
===================================================================
RCS file: /repository/curl/lib/http_digest.c,v
retrieving revision 1.14
diff -u -3 -H -r1.14 http_digest.c
--- lib/http_digest.c 4 May 2004 07:52:53 -0000 1.14
+++ lib/http_digest.c 6 May 2004 07:17:16 -0000
@@ -43,9 +43,7 @@
 #include <curl/mprintf.h>
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /* Test example headers:
 
@@ -105,7 +103,7 @@
          (2 == sscanf(header, "%31[^=]=%127[^,]",
                        value, content)) ) {
         if(strequal(value, "nonce")) {
- d->nonce = strdup(content);
+ d->nonce = curl_strdup(content);
         }
         else if(strequal(value, "stale")) {
           if(strequal(content, "true")) {
@@ -114,16 +112,16 @@
           }
         }
         else if(strequal(value, "realm")) {
- d->realm = strdup(content);
+ d->realm = curl_strdup(content);
         }
         else if(strequal(value, "opaque")) {
- d->opaque = strdup(content);
+ d->opaque = curl_strdup(content);
         }
         else if(strequal(value, "qop")) {
           char *tok_buf;
           /* tokenize the list and choose auth if possible, use a temporary
              clone of the buffer since strtok_r() ruins it */
- tmp = strdup(content);
+ tmp = curl_strdup(content);
           token = strtok_r(tmp, ",", &tok_buf);
           while (token != NULL) {
             if (strequal(token, "auth")) {
@@ -134,17 +132,17 @@
             }
             token = strtok_r(NULL, ",", &tok_buf);
           }
- free(tmp);
+ curl_free(tmp);
           /*select only auth o auth-int. Otherwise, ignore*/
           if (foundAuth) {
- d->qop = strdup("auth");
+ d->qop = curl_strdup("auth");
           }
           else if (foundAuthInt) {
- d->qop = strdup("auth-int");
+ d->qop = curl_strdup("auth-int");
           }
         }
         else if(strequal(value, "algorithm")) {
- d->algorithm = strdup(content);
+ d->algorithm = curl_strdup(content);
           if(strequal(content, "MD5-sess"))
             d->algo = CURLDIGESTALGO_MD5SESS;
           else if(strequal(content, "MD5"))
@@ -231,7 +229,7 @@
   }
   authp->done = TRUE;
 
- ha1 = (unsigned char *)malloc(33); /* 32 digits and 1 zero byte */
+ ha1 = (unsigned char *)curl_malloc(33); /* 32 digits and 1 zero byte */
 
   if(!d->nc)
     d->nc = 1;
@@ -258,14 +256,14 @@
   md5this = (unsigned char *)
     aprintf("%s:%s:%s", conn->user, d->realm, conn->passwd);
   Curl_md5it(md5buf, md5this);
- free(md5this); /* free this again */
+ curl_free(md5this); /* free this again */
   md5_to_ascii(md5buf, ha1);
 
   if(d->algo == CURLDIGESTALGO_MD5SESS) {
     /* nonce and cnonce are OUTSIDE the hash */
     tmp = aprintf("%s:%s:%s", ha1, d->nonce, d->cnonce);
 
- free(ha1);
+ curl_free(ha1);
     ha1 = (unsigned char *)tmp;
   }
 
@@ -289,7 +287,7 @@
     /* TODO: Append H(entity-body)*/
   }
   Curl_md5it(md5buf, md5this);
- free(md5this); /* free this again */
+ curl_free(md5this); /* free this again */
   md5_to_ascii(md5buf, ha2);
 
   if (d->qop) {
@@ -307,10 +305,10 @@
                                        d->nonce,
                                        ha2);
   }
- free(ha1);
+ curl_free(ha1);
 
   Curl_md5it(md5buf, md5this);
- free(md5this); /* free this again */
+ curl_free(md5this); /* free this again */
   md5_to_ascii(md5buf, request_digest);
 
   /* for test case 64 (snooped from a Mozilla 1.3a request)
@@ -367,21 +365,21 @@
   if(d->opaque) {
     /* append opaque */
     tmp = aprintf(", opaque=\"%s\"", d->opaque);
- *userp = (char*) realloc(*userp, strlen(*userp) + strlen(tmp) + 1);
+ *userp = (char*) curl_realloc(*userp, strlen(*userp) + strlen(tmp) + 1);
     strcat(*userp, tmp);
- free(tmp);
+ curl_free(tmp);
   }
 
   if(d->algorithm) {
     /* append algorithm */
     tmp = aprintf(", algorithm=\"%s\"", d->algorithm);
- *userp = (char*) realloc(*userp, strlen(*userp) + strlen(tmp) + 1);
+ *userp = (char*) curl_realloc(*userp, strlen(*userp) + strlen(tmp) + 1);
     strcat(conn->allocptr.userpwd, tmp);
- free(tmp);
+ curl_free(tmp);
   }
 
   /* append CRLF to the userpwd header */
- *userp = (char*) realloc(*userp, strlen(*userp) + 3 + 1);
+ *userp = (char*) curl_realloc(*userp, strlen(*userp) + 3 + 1);
   strcat(*userp, "\r\n");
 
   return CURLE_OK;
@@ -390,27 +388,27 @@
 void Curl_digest_cleanup_one(struct digestdata *d)
 {
   if(d->nonce)
- free(d->nonce);
+ curl_free(d->nonce);
   d->nonce = NULL;
 
   if(d->cnonce)
- free(d->cnonce);
+ curl_free(d->cnonce);
   d->cnonce = NULL;
 
   if(d->realm)
- free(d->realm);
+ curl_free(d->realm);
   d->realm = NULL;
 
   if(d->opaque)
- free(d->opaque);
+ curl_free(d->opaque);
   d->opaque = NULL;
 
   if(d->qop)
- free(d->qop);
+ curl_free(d->qop);
   d->qop = NULL;
 
   if(d->algorithm)
- free(d->algorithm);
+ curl_free(d->algorithm);
   d->algorithm = NULL;
 
   d->nc = 0;
Index: lib/http_negotiate.c
===================================================================
RCS file: /repository/curl/lib/http_negotiate.c,v
retrieving revision 1.8
diff -u -3 -H -r1.8 http_negotiate.c
--- lib/http_negotiate.c 27 Apr 2004 13:56:23 -0000 1.8
+++ lib/http_negotiate.c 6 May 2004 07:17:16 -0000
@@ -46,9 +46,7 @@
 #include <curl/mprintf.h>
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 static int
 get_gss_name(struct connectdata *conn, gss_name_t *server)
@@ -167,7 +165,7 @@
   if (len > 0) {
     int rawlen;
     input_token.length = (len+3)/4 * 3;
- input_token.value = malloc(input_token.length);
+ input_token.value = curl_malloc(input_token.length);
     if (input_token.value == NULL)
       return ENOMEM;
     rawlen = Curl_base64_decode(header, input_token.value);
@@ -184,7 +182,7 @@
         unsigned char * mechToken = NULL;
         size_t mechTokenLength = 0;
 
- spnegoToken = malloc(input_token.length);
+ spnegoToken = curl_malloc(input_token.length);
         if (input_token.value == NULL)
           return ENOMEM;
         spnegoTokenLength = input_token.length;
@@ -198,17 +196,17 @@
                                     &mechTokenLength,
                                     NULL,
                                     NULL)) {
- free(spnegoToken);
+ curl_free(spnegoToken);
           spnegoToken = NULL;
           infof(conn->data, "Parse SPNEGO Target Token failed\n");
         }
         else {
- free(input_token.value);
+ curl_free(input_token.value);
           input_token.value = NULL;
- input_token.value = malloc(mechTokenLength);
+ input_token.value = curl_malloc(mechTokenLength);
           memcpy(input_token.value, mechToken,mechTokenLength);
           input_token.length = mechTokenLength;
- free(mechToken);
+ curl_free(mechToken);
           mechToken = NULL;
           infof(conn->data, "Parse SPNEGO Target Token succeded\n");
         }
@@ -266,7 +264,7 @@
     unsigned char * responseToken = NULL;
     size_t responseTokenLength = 0;
     
- responseToken = malloc(neg_ctx->output_token.length);
+ responseToken = curl_malloc(neg_ctx->output_token.length);
     if ( responseToken == NULL)
       return CURLE_OUT_OF_MEMORY;
     memcpy(responseToken, neg_ctx->output_token.value,
@@ -279,17 +277,17 @@
                                  responseTokenLength,
                                  &spnegoToken,
                                  &spnegoTokenLength)) {
- free(responseToken);
+ curl_free(responseToken);
       responseToken = NULL;
       infof(conn->data, "Make SPNEGO Initial Token failed\n");
     }
     else {
- free(neg_ctx->output_token.value);
+ curl_free(neg_ctx->output_token.value);
       responseToken = NULL;
- neg_ctx->output_token.value = malloc(spnegoTokenLength);
+ neg_ctx->output_token.value = curl_malloc(spnegoTokenLength);
       memcpy(neg_ctx->output_token.value, spnegoToken,spnegoTokenLength);
       neg_ctx->output_token.length = spnegoTokenLength;
- free(spnegoToken);
+ curl_free(spnegoToken);
       spnegoToken = NULL;
       infof(conn->data, "Make SPNEGO Initial Token succeded\n");
     }
@@ -304,7 +302,7 @@
 
   conn->allocptr.userpwd =
     aprintf("Authorization: %s %s\r\n", neg_ctx->protocol, encoded);
- free(encoded);
+ curl_free(encoded);
   gss_release_buffer(&minor_status, &neg_ctx->output_token);
   return (conn->allocptr.userpwd == NULL) ? CURLE_OUT_OF_MEMORY : CURLE_OK;
 }
Index: lib/http_ntlm.c
===================================================================
RCS file: /repository/curl/lib/http_ntlm.c,v
retrieving revision 1.31
diff -u -3 -H -r1.31 http_ntlm.c
--- lib/http_ntlm.c 4 May 2004 07:52:53 -0000 1.31
+++ lib/http_ntlm.c 6 May 2004 07:17:17 -0000
@@ -71,9 +71,7 @@
 #endif
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /* Define this to make the type-3 message include the NT response message */
 #define USE_NTRESPONSES 1
@@ -215,7 +213,7 @@
   size_t len = strlen(password);
 
   /* make it fit at least 14 bytes */
- pw = malloc(len<7?14:len*2);
+ pw = curl_malloc(len<7?14:len*2);
   if(!pw)
     return; /* this will lead to a badly generated package */
 
@@ -267,7 +265,7 @@
   calc_resp(ntbuffer, nonce, ntresp);
 #endif
 
- free(pw);
+ curl_free(pw);
 }
 
 #define SHORTPAIR(x) ((x) & 0xff), ((x) >> 8)
@@ -386,7 +384,7 @@
       *allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n",
                               proxy?"Proxy-":"",
                               base64);
- free(base64);
+ curl_free(base64);
     }
     else
       return CURLE_OUT_OF_MEMORY; /* FIX TODO */
@@ -559,7 +557,7 @@
       *allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n",
                               proxy?"Proxy-":"",
                               base64);
- free(base64);
+ curl_free(base64);
     }
     else
       return CURLE_OUT_OF_MEMORY; /* FIX TODO */
@@ -573,7 +571,7 @@
     /* connection is already authenticated,
      * don't send a header in future requests */
     if(*allocuserpwd) {
- free(*allocuserpwd);
+ curl_free(*allocuserpwd);
       *allocuserpwd=NULL;
     }
     authp->done = TRUE;
Index: lib/if2ip.c
===================================================================
RCS file: /repository/curl/lib/if2ip.c,v
retrieving revision 1.33
diff -u -3 -H -r1.33 if2ip.c
--- lib/if2ip.c 5 May 2004 13:42:23 -0000 1.33
+++ lib/if2ip.c 6 May 2004 07:17:18 -0000
@@ -75,9 +75,7 @@
 #include "if2ip.h"
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 #define SYS_ERROR -1
 
Index: lib/krb4.c
===================================================================
RCS file: /repository/curl/lib/krb4.c,v
retrieving revision 1.36
diff -u -3 -H -r1.36 krb4.c
--- lib/krb4.c 28 Apr 2004 20:34:04 -0000 1.36
+++ lib/krb4.c 6 May 2004 07:17:19 -0000
@@ -66,9 +66,7 @@
 #endif
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 #define LOCAL_ADDR (&conn->local_addr)
 #define REMOTE_ADDR (&conn->serv_addr)
@@ -154,7 +152,7 @@
             struct connectdata *conn)
 {
   struct krb4_data *d = app_data;
- *to = malloc(length + 31);
+ *to = curl_malloc(length + 31);
   if(level == prot_safe)
     return krb_mk_safe(from, *to, length, &d->key,
                        (struct sockaddr_in *)LOCAL_ADDR,
@@ -257,7 +255,7 @@
 
   result = Curl_ftpsendf(conn, "ADAT %s", p);
 
- free(p);
+ curl_free(p);
 
   if(result)
     return -2;
@@ -393,7 +391,7 @@
   memset (tktcopy.dat, 0, tktcopy.length);
 
   result = Curl_ftpsendf(conn, "SITE KAUTH %s %s", name, p);
- free(p);
+ curl_free(p);
   if(result)
     return result;
 
Index: lib/ldap.c
===================================================================
RCS file: /repository/curl/lib/ldap.c,v
retrieving revision 1.36
diff -u -3 -H -r1.36 ldap.c
--- lib/ldap.c 5 May 2004 14:08:52 -0000 1.36
+++ lib/ldap.c 6 May 2004 07:17:20 -0000
@@ -60,9 +60,7 @@
 #define _MPRINTF_REPLACE /* use our functions only */
 #include <curl/mprintf.h>
 
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /* WLdap32.dll functions are *not* stdcall. Must call these via __cdecl
  * pointers in case libcurl was compiled as fastcall (-Gr).
@@ -424,9 +422,10 @@
   for (i = 2, s = strchr(str,','); s; i++)
      s = strchr(++s,',');
 
- res = calloc(i, sizeof(char*));
+ res = curl_malloc(i*sizeof(char*));
   if (!res)
     return NULL;
+ memset(res,0,i*sizeof(char*));
 
   for (i = 0, s = strtok_r(str, ",", &lasts); s;
        s = strtok_r(NULL, ",", &lasts), i++)
@@ -463,7 +462,7 @@
     char *dn = ludp->lud_dn;
     char *new_dn = curl_unescape(dn, 0);
 
- free(dn);
+ curl_free(dn);
     if (!new_dn)
        return (FALSE);
     ludp->lud_dn = new_dn;
@@ -498,7 +497,7 @@
 
   /* parse DN (Distinguished Name).
    */
- ludp->lud_dn = strdup(conn->path+1);
+ ludp->lud_dn = curl_strdup(conn->path+1);
   if (!ludp->lud_dn)
      return LDAP_NO_MEMORY;
 
@@ -580,12 +579,13 @@
 static int _ldap_url_parse (const struct connectdata *conn,
                             LDAPURLDesc **ludpp)
 {
- LDAPURLDesc *ludp = calloc(sizeof(*ludp), 1);
+ LDAPURLDesc *ludp = curl_malloc(sizeof(*ludp));
   int rc;
 
   *ludpp = NULL;
   if (!ludp)
      return LDAP_NO_MEMORY;
+ memset(ludp,0,sizeof(*ludp));
 
   rc = _ldap_url_parse2 (conn, ludp);
   if (rc != LDAP_SUCCESS) {
@@ -604,23 +604,23 @@
      return;
 
   if (ludp->lud_dn)
- free(ludp->lud_dn);
+ curl_free(ludp->lud_dn);
 
   if (ludp->lud_filter)
- free(ludp->lud_filter);
+ curl_free(ludp->lud_filter);
 
   if (ludp->lud_attrs) {
     for (i = 0; ludp->lud_attrs[i]; i++)
- free(ludp->lud_attrs[i]);
- free(ludp->lud_attrs);
+ curl_free(ludp->lud_attrs[i]);
+ curl_free(ludp->lud_attrs);
   }
 
   if (ludp->lud_exts) {
     for (i = 0; ludp->lud_exts[i]; i++)
- free(ludp->lud_exts[i]);
- free(ludp->lud_exts);
+ curl_free(ludp->lud_exts[i]);
+ curl_free(ludp->lud_exts);
   }
- free (ludp);
+ curl_free (ludp);
 }
 #endif /* WIN32 */
 #endif /* CURL_DISABLE_LDAP */
Index: lib/llist.c
===================================================================
RCS file: /repository/curl/lib/llist.c,v
retrieving revision 1.12
diff -u -3 -H -r1.12 llist.c
--- lib/llist.c 7 Jan 2004 09:19:35 -0000 1.12
+++ lib/llist.c 6 May 2004 07:17:20 -0000
@@ -28,10 +28,9 @@
 
 #include "llist.h"
 
-#ifdef CURLDEBUG
 /* this must be the last include file */
 #include "memdebug.h"
-#endif
+
 void
 Curl_llist_init(curl_llist *l, curl_llist_dtor dtor)
 {
@@ -46,7 +45,7 @@
 {
   curl_llist *list;
 
- list = (curl_llist *)malloc(sizeof(curl_llist));
+ list = (curl_llist *)curl_malloc(sizeof(curl_llist));
   if(NULL == list)
     return NULL;
 
@@ -60,7 +59,7 @@
 {
   curl_llist_element *ne;
 
- ne = (curl_llist_element *) malloc(sizeof(curl_llist_element));
+ ne = (curl_llist_element *) curl_malloc(sizeof(curl_llist_element));
   ne->ptr = (void *) p;
   if (list->size == 0) {
     list->head = ne;
@@ -89,7 +88,7 @@
 {
   curl_llist_element *ne;
 
- ne = (curl_llist_element *) malloc(sizeof(curl_llist_element));
+ ne = (curl_llist_element *) curl_malloc(sizeof(curl_llist_element));
   ne->ptr = (void *) p;
   if (list->size == 0) {
     list->head = ne;
@@ -134,7 +133,7 @@
   }
 
   list->dtor(user, e->ptr);
- free(e);
+ curl_free(e);
   --list->size;
 
   return 1;
@@ -167,6 +166,6 @@
     while (list->size > 0)
       Curl_llist_remove(list, list->tail, user);
 
- free(list);
+ curl_free(list);
   }
 }
Index: lib/memdebug.c
===================================================================
RCS file: /repository/curl/lib/memdebug.c,v
retrieving revision 1.43
diff -u -3 -H -r1.43 memdebug.c
--- lib/memdebug.c 5 May 2004 13:41:54 -0000 1.43
+++ lib/memdebug.c 6 May 2004 07:17:22 -0000
@@ -133,32 +133,6 @@
   return (mem ? mem->mem : NULL);
 }
 
-void *curl_docalloc(size_t wanted_elements, size_t wanted_size,
- int line, const char *source)
-{
- struct memdebug *mem;
- size_t size, user_size;
-
- if(countcheck("calloc", line, source))
- return NULL;
-
- /* alloc at least 64 bytes */
- user_size = wanted_size * wanted_elements;
- size = sizeof(struct memdebug) + user_size;
-
- mem = (struct memdebug *)(malloc)(size);
- if(mem) {
- /* fill memory with zeroes */
- memset(mem->mem, 0, user_size);
- mem->size = user_size;
- }
-
- if(logfile && source)
- fprintf(logfile, "MEM %s:%d calloc(%u,%u) = %p\n",
- source, line, wanted_elements, wanted_size, mem ? mem->mem : 0);
- return (mem ? mem->mem : NULL);
-}
-
 char *curl_dostrdup(const char *str, int line, const char *source)
 {
   char *mem;
@@ -282,11 +256,63 @@
             source, line, file);
   return res;
 }
-#else
+
+#else /* !CURLDEBUG */
+
+#include "memdebug.h"
+
 #ifdef VMS
 int VOID_VAR_MEMDEBUG;
 #else
 /* we provide a fake do-nothing function here to avoid compiler warnings */
-void curl_memdebug(void) {}
+void curl_memdebug(const char *logname) {}
 #endif /* VMS */
+
+#ifdef CURL_MEMCALLBACK /* !CURLDEBUG && CURL_MEMCALLBACK */
+
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * Set the default values for the callback functions.
+ */
+curlMallocFunc curl_malloc = malloc;
+curlFreeFunc curl_free = free;
+curlReallocFunc curl_realloc = realloc;
+curlStrdupFunc curl_strdup = strdup;
+
+int curl_set_memory_callbacks(curlMallocFunc m,curlFreeFunc f,
+ curlReallocFunc r,curlStrdupFunc s ) {
+ if ( m == NULL || f == NULL || r == NULL || s == NULL ) {
+ return -1;
+ }
+
+ curl_malloc = m;
+ curl_free = f;
+ curl_realloc = r;
+ curl_strdup = s;
+ return 0;
+}
+
+#endif /* CURL_MEMCALLBACK */
 #endif /* CURLDEBUG */
+
+#include "config.h"
+#ifndef HAVE_STRDUP
+#include <stdio.h>
+/* Ultrix doesn't have strdup(), so make a quick clone: */
+char *strdup(char *str)
+{
+ int len;
+ char *newstr;
+
+ len = strlen(str);
+ newstr = (char *) curl_malloc((len+1)*sizeof(char));
+ if (!newstr)
+ return (char *)NULL;
+
+ strcpy(newstr,str);
+
+ return newstr;
+}
+#endif
Index: lib/memdebug.h
===================================================================
RCS file: /repository/curl/lib/memdebug.h,v
retrieving revision 1.27
diff -u -3 -H -r1.27 memdebug.h
--- lib/memdebug.h 26 Apr 2004 07:20:11 -0000 1.27
+++ lib/memdebug.h 6 May 2004 07:17:22 -0000
@@ -1,6 +1,7 @@
-#ifdef CURLDEBUG
 #ifndef _CURL_MEDEBUG_H
 #define _CURL_MEDEBUG_H
+
+#ifdef CURLDEBUG
 /***************************************************************************
  * _ _ ____ _
  * Project ___| | | | _ \| |
@@ -49,7 +50,6 @@
 
 /* memory functions */
 void *curl_domalloc(size_t size, int line, const char *source);
-void *curl_docalloc(size_t elements, size_t size, int line, const char *source);
 void *curl_dorealloc(void *ptr, size_t size, int line, const char *source);
 void curl_dofree(void *ptr, int line, const char *source);
 char *curl_dostrdup(const char *str, int line, const char *source);
@@ -69,14 +69,6 @@
 
 #ifndef MEMDEBUG_NODEFINES
 
-/* Set this symbol on the command-line, recompile all lib-sources */
-#undef strdup
-#define strdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__)
-#define malloc(size) curl_domalloc(size, __LINE__, __FILE__)
-#define calloc(nbelem,size) curl_docalloc(nbelem, size, __LINE__, __FILE__)
-#define realloc(ptr,size) curl_dorealloc(ptr, size, __LINE__, __FILE__)
-#define free(ptr) curl_dofree(ptr, __LINE__, __FILE__)
-
 #define socket(domain,type,protocol)\
  curl_socket(domain,type,protocol,__LINE__,__FILE__)
 #undef accept /* for those with accept as a macro */
@@ -104,5 +96,31 @@
 
 #endif /* MEMDEBUG_NODEFINES */
 
-#endif /* _CURL_MEDEBUG_H */
+#define curl_malloc(size) curl_domalloc(size, __LINE__, __FILE__)
+#define curl_free(ptr) curl_dofree(ptr, __LINE__, __FILE__)
+#define curl_realloc(ptr,size) curl_dorealloc(ptr, size, __LINE__, __FILE__)
+#define curl_strdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__)
+
+#else /* !CURLDEBUG */
+
+#ifdef CURL_MEMCALLBACK /* !CURLDEBUG && CURL_MEMCALLBACK */
+
+#include <curl/curl.h> /* For curlMallocFunc etc definitions */
+
+extern curlMallocFunc curl_malloc;
+extern curlFreeFunc curl_free;
+extern curlReallocFunc curl_realloc;
+extern curlStrdupFunc curl_strdup;
+
+#else /* !CURLDEBUG && !CURL_MEMCALLBACK */
+
+#define curl_malloc(size) malloc(size)
+#define curl_free(ptr) free(ptr)
+#define curl_realloc(ptr,size) realloc(ptr, size)
+#define curl_strdup(ptr) strdup(ptr)
+
+#endif /* CURL_MEMCALLBACK */
+
 #endif /* CURLDEBUG */
+
+#endif /* _CURL_MEDEBUG_H */
Index: lib/mprintf.c
===================================================================
RCS file: /repository/curl/lib/mprintf.c,v
retrieving revision 1.40
diff -u -3 -H -r1.40 mprintf.c
--- lib/mprintf.c 5 May 2004 06:57:26 -0000 1.40
+++ lib/mprintf.c 6 May 2004 07:17:23 -0000
@@ -56,9 +56,7 @@
 #endif
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 #define BUFFSIZE 256 /* buffer for long-to-str and float-to-str calcs */
 #define MAX_PARAMETERS 128 /* lame static limit */
@@ -1031,7 +1029,7 @@
   struct asprintf *infop=(struct asprintf *)data;
  
   if(!infop->buffer) {
- infop->buffer=(char *)malloc(32);
+ infop->buffer=(char *)curl_malloc(32);
     if(!infop->buffer)
       return -1; /* fail */
     infop->alloc = 32;
@@ -1040,7 +1038,7 @@
   else if(infop->len+1 >= infop->alloc) {
     char *newptr;
 
- newptr = (char *)realloc(infop->buffer, infop->alloc*2);
+ newptr = (char *)curl_realloc(infop->buffer, infop->alloc*2);
 
     if(!newptr) {
       return -1;
@@ -1071,7 +1069,7 @@
   va_end(ap_save);
   if(-1 == retcode) {
     if(info.alloc)
- free(info.buffer);
+ curl_free(info.buffer);
     return NULL;
   }
   if(info.alloc) {
@@ -1079,7 +1077,7 @@
     return info.buffer;
   }
   else
- return strdup("");
+ return curl_strdup("");
 }
 
 char *curl_mvaprintf(const char *format, va_list ap_save)
@@ -1094,7 +1092,7 @@
   retcode = dprintf_formatf(&info, alloc_addbyter, format, ap_save);
   if(-1 == retcode) {
     if(info.alloc)
- free(info.buffer);
+ curl_free(info.buffer);
     return NULL;
   }
 
@@ -1103,7 +1101,7 @@
     return info.buffer;
   }
   else
- return strdup("");
+ return curl_strdup("");
 }
 
 static int storebuffer(int output, FILE *data)
@@ -1187,7 +1185,7 @@
 
   memset(ptr, 55, strlen(ptr)+1);
 
- free(ptr);
+ curl_free(ptr);
 
 #if 1
   curl_mprintf(buffer, "%s %s %d", "daniel", "stenberg", 19988);
Index: lib/multi.c
===================================================================
RCS file: /repository/curl/lib/multi.c,v
retrieving revision 1.50
diff -u -3 -H -r1.50 multi.c
--- lib/multi.c 26 Apr 2004 07:20:11 -0000 1.50
+++ lib/multi.c 6 May 2004 07:17:24 -0000
@@ -44,9 +44,7 @@
 #include "progress.h"
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 struct Curl_message {
   /* the 'CURLMsg' is the part that is visible to the external user */
@@ -115,7 +113,7 @@
 {
   struct Curl_multi *multi;
 
- multi = (void *)malloc(sizeof(struct Curl_multi));
+ multi = (void *)curl_malloc(sizeof(struct Curl_multi));
 
   if(multi) {
     memset(multi, 0, sizeof(struct Curl_multi));
@@ -125,7 +123,7 @@
   multi->hostcache = Curl_mk_dnscache();
   if(!multi->hostcache) {
     /* failure, free mem and bail out */
- free(multi);
+ curl_free(multi);
     multi = NULL;
   }
   return (CURLM *) multi;
@@ -146,7 +144,7 @@
     return CURLM_BAD_EASY_HANDLE;
 
   /* Now, time to add an easy handle to the multi stack */
- easy = (struct Curl_one_easy *)malloc(sizeof(struct Curl_one_easy));
+ easy = (struct Curl_one_easy *)curl_malloc(sizeof(struct Curl_one_easy));
   if(!easy)
     return CURLM_OUT_OF_MEMORY;
   
@@ -217,8 +215,8 @@
     /* NOTE NOTE NOTE
        We do not touch the easy handle here! */
     if (easy->msg)
- free(easy->msg);
- free(easy);
+ curl_free(easy->msg);
+ curl_free(easy);
 
     multi->num_easy--; /* one less to care about now */
 
@@ -332,13 +330,13 @@
 
         easy->result = Curl_done(easy->easy_conn);
         if(CURLE_OK == easy->result) {
- gotourl = strdup(easy->easy_handle->change.url);
+ gotourl = curl_strdup(easy->easy_handle->change.url);
           easy->easy_handle->change.url_changed = FALSE;
           easy->result = Curl_follow(easy->easy_handle, gotourl);
           if(CURLE_OK == easy->result)
             easy->state = CURLM_STATE_CONNECT;
           else
- free(gotourl);
+ curl_free(gotourl);
         }
       }
     
@@ -557,7 +555,7 @@
       easy->easy_handle->hostcache = NULL;
 
       /* now add a node to the Curl_message linked list with this info */
- msg = (struct Curl_message *)malloc(sizeof(struct Curl_message));
+ msg = (struct Curl_message *)curl_malloc(sizeof(struct Curl_message));
 
       if(!msg)
         return CURLM_OUT_OF_MEMORY;
@@ -597,12 +595,12 @@
       easy->easy_handle->hostcache = NULL;
 
       if (easy->msg)
- free(easy->msg);
- free(easy);
+ curl_free(easy->msg);
+ curl_free(easy);
       easy = nexteasy;
     }
 
- free(multi);
+ curl_free(multi);
 
     return CURLM_OK;
   }
Index: lib/netrc.c
===================================================================
RCS file: /repository/curl/lib/netrc.c,v
retrieving revision 1.31
diff -u -3 -H -r1.31 netrc.c
--- lib/netrc.c 23 Mar 2004 15:30:12 -0000 1.31
+++ lib/netrc.c 6 May 2004 07:17:24 -0000
@@ -50,9 +50,7 @@
 #include <curl/mprintf.h>
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /* Debug this single source file with:
    'make netrc' then run './netrc'!
@@ -135,7 +133,7 @@
     netrcfile = curl_maprintf("%s%s%s", home, DIR_CHAR, NETRC);
     if(!netrcfile) {
       if(home_alloc)
- free(home);
+ curl_free(home);
       return -1;
     }
     netrc_alloc = TRUE;
@@ -223,9 +221,9 @@
   }
 
   if(home_alloc)
- free(home);
+ curl_free(home);
   if(netrc_alloc)
- free(netrcfile);
+ curl_free(netrcfile);
 
   return retcode;
 }
Index: lib/nwlib.c
===================================================================
RCS file: /repository/curl/lib/nwlib.c,v
retrieving revision 1.2
diff -u -3 -H -r1.2 nwlib.c
--- lib/nwlib.c 17 Mar 2004 13:36:45 -0000 1.2
+++ lib/nwlib.c 6 May 2004 07:17:25 -0000
@@ -30,6 +30,7 @@
 #include <nks/thread.h>
 #include <nks/synch.h>
 
+#include "memdebug.h"
 
 typedef struct
 {
@@ -188,13 +189,13 @@
 
         if (!(app_data = (libdata_t *) get_app_data(id)))
         {
- app_data = (libdata_t *) malloc(sizeof(libdata_t));
+ app_data = (libdata_t *) curl_malloc(sizeof(libdata_t));
 
             if (app_data)
             {
                 memset(app_data, 0, sizeof(libdata_t));
 
- app_data->tenbytes = malloc(10);
+ app_data->tenbytes = curl_malloc(10);
                 app_data->lock = NXMutexAlloc(0, 0, &liblock);
 
                 if (!app_data->tenbytes || !app_data->lock)
@@ -202,7 +203,7 @@
                     if (app_data->lock)
                         NXMutexFree(app_data->lock);
 
- free(app_data);
+ curl_free(app_data);
                     app_data = (libdata_t *) NULL;
                     err = ENOMEM;
                 }
@@ -220,7 +221,7 @@
 
                     if (err)
                     {
- free(app_data);
+ curl_free(app_data);
                         app_data = (libdata_t *) NULL;
                         err = ENOMEM;
                     }
@@ -256,24 +257,24 @@
 ** important, this just helps to demonstrate that we can have arbitrarily
 ** complex per-thread data.
 */
- thread_data = (libthreaddata_t *) malloc(sizeof(libthreaddata_t));
+ thread_data = (libthreaddata_t *) curl_malloc(sizeof(libthreaddata_t));
 
             if (thread_data)
             {
                 thread_data->_errno = 0;
- thread_data->twentybytes = malloc(20);
+ thread_data->twentybytes = curl_malloc(20);
 
                 if (!thread_data->twentybytes)
                 {
- free(thread_data);
+ curl_free(thread_data);
                     thread_data = (libthreaddata_t *) NULL;
                     err = ENOMEM;
                 }
 
                 if ((err = NXKeySetValue(key, thread_data)))
                 {
- free(thread_data->twentybytes);
- free(thread_data);
+ curl_free(thread_data->twentybytes);
+ curl_free(thread_data);
                     thread_data = (libthreaddata_t *) NULL;
                 }
             }
@@ -299,9 +300,9 @@
         void *tenbytes = ((libdata_t *) data)->tenbytes;
 
         if (tenbytes)
- free(tenbytes);
+ curl_free(tenbytes);
 
- free(data);
+ curl_free(data);
     }
 
     return 0;
@@ -317,9 +318,9 @@
         void *twentybytes = ((libthreaddata_t *) data)->twentybytes;
 
         if (twentybytes)
- free(twentybytes);
+ curl_free(twentybytes);
 
- free(data);
+ curl_free(data);
     }
 }
 
Index: lib/security.c
===================================================================
RCS file: /repository/curl/lib/security.c,v
retrieving revision 1.23
diff -u -3 -H -r1.23 security.c
--- lib/security.c 2 Dec 2003 13:27:29 -0000 1.23
+++ lib/security.c 6 May 2004 07:17:26 -0000
@@ -60,9 +60,7 @@
 #include "ftp.h"
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 #define min(a, b) ((a) < (b) ? (a) : (b))
 
@@ -154,7 +152,7 @@
   else if (b < 0)
     return -1;
   len = ntohl(len);
- buf->data = realloc(buf->data, len);
+ buf->data = curl_realloc(buf->data, len);
   b = block_read(fd, buf->data, len);
   if (b == 0)
     return 0;
@@ -181,9 +179,9 @@
     if(buf->index + len > buf->size) {
         void *tmp;
         if(buf->data == NULL)
- tmp = malloc(1024);
+ tmp = curl_malloc(1024);
         else
- tmp = realloc(buf->data, buf->index + len);
+ tmp = curl_realloc(buf->data, buf->index + len);
         if(tmp == NULL)
             return -1;
         buf->data = tmp;
@@ -239,7 +237,7 @@
   bytes = htonl(bytes);
   block_write(fd, &bytes, sizeof(bytes));
   block_write(fd, buf, ntohl(bytes));
- free(buf);
+ curl_free(buf);
   return length;
 }
 
@@ -301,7 +299,7 @@
     char *buf;
     int code;
     
- buf = malloc(strlen(s));
+ buf = curl_malloc(strlen(s));
     len = Curl_base64_decode(s + 4, buf); /* XXX */
     
     len = (conn->mech->decode)(conn->app_data, buf, len, level, conn);
@@ -317,7 +315,7 @@
     if(buf[len-1] == '\n')
         buf[len-1] = '\0';
     strcpy(s, buf);
- free(buf);
+ curl_free(buf);
     return code;
 }
 
@@ -407,7 +405,7 @@
   for(m = mechs; *m && (*m)->name; m++) {
     void *tmp;
 
- tmp = realloc(conn->app_data, (*m)->size);
+ tmp = curl_realloc(conn->app_data, (*m)->size);
     if (tmp == NULL) {
       failf (data, "realloc %u failed", (*m)->size);
       return -1;
@@ -470,7 +468,7 @@
     if(conn->mech->end)
       (conn->mech->end)(conn->app_data);
     memset(conn->app_data, 0, conn->mech->size);
- free(conn->app_data);
+ curl_free(conn->app_data);
     conn->app_data = NULL;
   }
   conn->sec_complete = 0;
Index: lib/sendf.c
===================================================================
RCS file: /repository/curl/lib/sendf.c,v
retrieving revision 1.82
diff -u -3 -H -r1.82 sendf.c
--- lib/sendf.c 5 May 2004 07:01:33 -0000 1.82
+++ lib/sendf.c 6 May 2004 07:17:27 -0000
@@ -53,9 +53,7 @@
 #endif
 #include <string.h>
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /* returns last node in linked list */
 static struct curl_slist *slist_get_last(struct curl_slist *list)
@@ -85,10 +83,10 @@
   struct curl_slist *last;
   struct curl_slist *new_item;
 
- new_item = (struct curl_slist *) malloc(sizeof(struct curl_slist));
+ new_item = (struct curl_slist *) curl_malloc(sizeof(struct curl_slist));
   if (new_item) {
     new_item->next = NULL;
- new_item->data = strdup(data);
+ new_item->data = curl_strdup(data);
   }
   if (new_item == NULL || new_item->data == NULL) {
     return NULL;
@@ -118,9 +116,9 @@
     next = item->next;
                 
     if (item->data) {
- free(item->data);
+ curl_free(item->data);
     }
- free(item);
+ curl_free(item);
     item = next;
   } while (next);
 }
@@ -209,7 +207,7 @@
       break;
   }
 
- free(s); /* free the output string */
+ curl_free(s); /* free the output string */
 
   return res;
 }
Index: lib/share.c
===================================================================
RCS file: /repository/curl/lib/share.c,v
retrieving revision 1.17
diff -u -3 -H -r1.17 share.c
--- lib/share.c 30 Mar 2004 13:02:31 -0000 1.17
+++ lib/share.c 6 May 2004 07:17:27 -0000
@@ -30,15 +30,13 @@
 #include "share.h"
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 CURLSH *
 curl_share_init(void)
 {
   struct Curl_share *share =
- (struct Curl_share *)malloc(sizeof(struct Curl_share));
+ (struct Curl_share *)curl_malloc(sizeof(struct Curl_share));
   if (share) {
     memset (share, 0, sizeof(struct Curl_share));
     share->specifier |= (1<<CURL_LOCK_DATA_SHARE);
@@ -170,7 +168,7 @@
     Curl_cookie_cleanup(share->cookies);
 
   share->unlockfunc(NULL, CURL_LOCK_DATA_SHARE, share->clientdata);
- free (share);
+ curl_free (share);
   
   return CURLSHE_OK;
 }
Index: lib/ssluse.c
===================================================================
RCS file: /repository/curl/lib/ssluse.c,v
retrieving revision 1.98
diff -u -3 -H -r1.98 ssluse.c
--- lib/ssluse.c 29 Apr 2004 07:36:40 -0000 1.98
+++ lib/ssluse.c 6 May 2004 07:17:29 -0000
@@ -51,9 +51,7 @@
 #include <openssl/x509v3.h>
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 #if OPENSSL_VERSION_NUMBER >= 0x0090581fL
 #define HAVE_SSL_GET1_SESSION 1
@@ -192,7 +190,7 @@
       len = (int)strlen(area);
       RAND_add(area, len, (len >> 1));
 
- free(area); /* now remove the random junk */
+ curl_free(area); /* now remove the random junk */
     } while (!RAND_status());
   }
 #endif
@@ -513,7 +511,7 @@
     return CURLE_OK;
 
   session = (struct curl_ssl_session *)
- malloc(amount * sizeof(struct curl_ssl_session));
+ curl_malloc(amount * sizeof(struct curl_ssl_session));
   if(!session)
     return CURLE_OUT_OF_MEMORY;
 
@@ -573,7 +571,7 @@
 
     Curl_free_ssl_config(&session->ssl_config);
 
- free(session->name);
+ curl_free(session->name);
     session->name = NULL; /* no name */
 
     return 0; /* ok */
@@ -596,7 +594,7 @@
       Kill_Single_Session(&data->state.session[i]);
     
     /* free the cache data */
- free(data->state.session);
+ curl_free(data->state.session);
   }
 #ifdef HAVE_OPENSSL_ENGINE_H
   if(data->engine)
@@ -662,7 +660,7 @@
   /* now init the session struct wisely */
   store->sessionid = ssl_sessionid;
   store->age = data->state.sessionage; /* set current age */
- store->name = strdup(conn->host.name); /* clone host name */
+ store->name = curl_strdup(conn->host.name); /* clone host name */
   store->remote_port = conn->remote_port; /* port number */
 
   Curl_clone_ssl_config(&conn->ssl_config, &store->ssl_config);
Index: lib/telnet.c
===================================================================
RCS file: /repository/curl/lib/telnet.c,v
retrieving revision 1.59
diff -u -3 -H -r1.59 telnet.c
--- lib/telnet.c 26 Apr 2004 07:50:51 -0000 1.59
+++ lib/telnet.c 6 May 2004 07:17:32 -0000
@@ -83,9 +83,7 @@
 #include "arpa_telnet.h"
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 #define SUBBUFSIZE 512
 
@@ -213,7 +211,7 @@
 {
   struct TELNET *tn;
 
- tn = (struct TELNET *)malloc(sizeof(struct TELNET));
+ tn = (struct TELNET *)curl_malloc(sizeof(struct TELNET));
   if(!tn)
     return CURLE_OUT_OF_MEMORY;
   
@@ -826,7 +824,7 @@
 
       /* Environment variable */
       if(curl_strequal(option_keyword, "NEW_ENV")) {
- buf = strdup(option_arg);
+ buf = curl_strdup(option_arg);
         if(!buf)
           return CURLE_OUT_OF_MEMORY;
         tn->telnet_vars = curl_slist_append(tn->telnet_vars, buf);
@@ -1069,7 +1067,7 @@
   struct TELNET *tn = (struct TELNET *)conn->proto.telnet;
   curl_slist_free_all(tn->telnet_vars);
 
- free(conn->proto.telnet);
+ curl_free(conn->proto.telnet);
   conn->proto.telnet = NULL;
 
   return CURLE_OK;
Index: lib/transfer.c
===================================================================
RCS file: /repository/curl/lib/transfer.c,v
retrieving revision 1.226
diff -u -3 -H -r1.226 transfer.c
--- lib/transfer.c 5 May 2004 06:57:26 -0000 1.226
+++ lib/transfer.c 6 May 2004 07:17:38 -0000
@@ -106,9 +106,7 @@
 #include <curl/mprintf.h>
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 #define CURL_TIMEOUT_EXPECT_100 1000 /* counting ms here */
 
@@ -315,7 +313,7 @@
                 long newsize=CURLMAX((k->hbuflen+nread)*3/2,
                                      data->state.headersize*2);
                 hbufp_index = k->hbufp - data->state.headerbuff;
- newbuff = (char *)realloc(data->state.headerbuff, newsize);
+ newbuff = (char *)curl_realloc(data->state.headerbuff, newsize);
                 if(!newbuff) {
                   failf (data, "Failed to alloc memory for big header!");
                   return CURLE_OUT_OF_MEMORY;
@@ -360,7 +358,7 @@
               long newsize=CURLMAX((k->hbuflen+full_length)*3/2,
                                    data->state.headersize*2);
               hbufp_index = k->hbufp - data->state.headerbuff;
- newbuff = (char *)realloc(data->state.headerbuff, newsize);
+ newbuff = (char *)curl_realloc(data->state.headerbuff, newsize);
               if(!newbuff) {
                 failf (data, "Failed to alloc memory for big header!");
                 return CURLE_OUT_OF_MEMORY;
@@ -689,7 +687,7 @@
                 /* allocate memory of a cloned copy */
                 Curl_safefree(data->info.contenttype);
               
- data->info.contenttype = malloc(len + 1);
+ data->info.contenttype = curl_malloc(len + 1);
                 if (NULL == data->info.contenttype)
                   return CURLE_OUT_OF_MEMORY;
 
@@ -852,7 +850,7 @@
                 backup = *ptr; /* store the ending letter */
                 if(ptr != start) {
                   *ptr = '\0'; /* zero terminate */
- conn->newurl = strdup(start); /* clone string */
+ conn->newurl = curl_strdup(start); /* clone string */
                   *ptr = backup; /* restore ending letter */
                 }
               }
@@ -1144,7 +1142,7 @@
           /* convert LF to CRLF if so asked */
           if (data->set.crlf) {
               if(data->state.scratch == NULL)
- data->state.scratch = malloc(2*BUFSIZE);
+ data->state.scratch = curl_malloc(2*BUFSIZE);
               if(data->state.scratch == NULL) {
                 failf (data, "Failed to alloc scratch buffer!");
                 return CURLE_OUT_OF_MEMORY;
@@ -1665,9 +1663,9 @@
 
     if(data->change.referer_alloc)
       /* If we already have an allocated referer, free this first */
- free(data->change.referer);
+ curl_free(data->change.referer);
 
- data->change.referer = strdup(data->change.url);
+ data->change.referer = curl_strdup(data->change.url);
     data->change.referer_alloc = TRUE; /* yes, free this later */
   }
 
@@ -1688,7 +1686,7 @@
 
     /* we must make our own copy of the URL to play with, as it may
        point to read-only data */
- char *url_clone=strdup(data->change.url);
+ char *url_clone=curl_strdup(data->change.url);
 
     if(!url_clone)
       return CURLE_OUT_OF_MEMORY; /* skip out of this NOW */
@@ -1775,7 +1773,7 @@
 
     urllen = strlen(url_clone);
     
- newest=(char *)malloc( urllen + 1 + /* possible slash */
+ newest=(char *)curl_malloc( urllen + 1 + /* possible slash */
                            newlen + 1 /* zero byte */);
     
     if(!newest)
@@ -1793,8 +1791,8 @@
     /* then append the new piece on the right side */
     strcpy_url(&newest[urllen], useurl);
 
- free(newurl); /* newurl is the allocated pointer */
- free(url_clone);
+ curl_free(newurl); /* newurl is the allocated pointer */
+ curl_free(url_clone);
     newurl = newest;
   }
   else {
@@ -1806,11 +1804,11 @@
          redirect but we still make an effort to do "right". */
       newlen = strlen_url(newurl);
 
- newest = malloc(newlen+1); /* get memory for this */
+ newest = curl_malloc(newlen+1); /* get memory for this */
       if(newest) {
         strcpy_url(newest, newurl); /* create a space-free URL */
 
- free(newurl); /* that was no good */
+ curl_free(newurl); /* that was no good */
         newurl = newest; /* use this instead now */
       }
     }
@@ -1818,7 +1816,7 @@
   }
 
   if(data->change.url_alloc)
- free(data->change.url);
+ curl_free(data->change.url);
   else
     data->change.url_alloc = TRUE; /* the URL is allocated */
       
@@ -1968,10 +1966,10 @@
       if ((CURLE_OK == res) && urlchanged) {
         res = Curl_done(conn);
         if(CURLE_OK == res) {
- char *gotourl = strdup(data->change.url);
+ char *gotourl = curl_strdup(data->change.url);
           res = Curl_follow(data, gotourl);
           if(res)
- free(gotourl);
+ curl_free(gotourl);
         }
       }
     } while (urlchanged && res == CURLE_OK) ;
@@ -1991,7 +1989,7 @@
                from it again. Bad luck. Retry the same request on a fresh
                connect! */
             infof(data, "Connection died, retrying a fresh connect\n");
- newurl = strdup(conn->data->change.url);
+ newurl = curl_strdup(conn->data->change.url);
 
             conn->bits.close = TRUE; /* close this connection */
             conn->bits.retry = TRUE; /* mark this as a connection we're about
@@ -2005,7 +2003,7 @@
              * We must duplicate the new URL here as the connection data
              * may be free()ed in the Curl_done() function.
              */
- newurl = conn->newurl?strdup(conn->newurl):NULL;
+ newurl = conn->newurl?curl_strdup(conn->newurl):NULL;
         }
         else {
           /* The transfer phase returned error, we mark the connection to get
@@ -2047,7 +2045,7 @@
   } while(1); /* loop if Location: */
 
   if(newurl)
- free(newurl);
+ curl_free(newurl);
 
   /* run post-transfer uncondionally, but don't clobber the return code if
      we already have an error code recorder */
Index: lib/url.c
===================================================================
RCS file: /repository/curl/lib/url.c,v
retrieving revision 1.371
diff -u -3 -H -r1.371 url.c
--- lib/url.c 5 May 2004 07:17:37 -0000 1.371
+++ lib/url.c 6 May 2004 07:17:41 -0000
@@ -136,9 +136,7 @@
 #endif
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /* Local static prototypes */
 static int ConnectionKillOne(struct SessionHandle *data);
@@ -176,7 +174,7 @@
 void Curl_safefree(void *ptr)
 {
   if(ptr)
- free(ptr);
+ curl_free(ptr);
 }
 
 /*
@@ -205,13 +203,13 @@
   Curl_safefree(data->state.scratch);
 
   if(data->change.proxy_alloc)
- free(data->change.proxy);
+ curl_free(data->change.proxy);
 
   if(data->change.referer_alloc)
- free(data->change.referer);
+ curl_free(data->change.referer);
 
   if(data->change.url_alloc)
- free(data->change.url);
+ curl_free(data->change.url);
 
   Curl_safefree(data->state.headerbuff);
 
@@ -231,7 +229,7 @@
 #endif
 
   /* free the connection cache */
- free(data->state.connects);
+ curl_free(data->state.connects);
 
   Curl_safefree(data->info.contenttype);
 
@@ -246,7 +244,7 @@
   if (data->share)
     data->share->dirty--;
 
- free(data);
+ curl_free(data);
   return CURLE_OK;
 }
 
@@ -263,7 +261,7 @@
   /* We don't yet support specifying the URL at this point */
   struct SessionHandle *data;
   /* Very simple start-up: alloc the struct, init it with zeroes and return */
- data = (struct SessionHandle *)malloc(sizeof(struct SessionHandle));
+ data = (struct SessionHandle *)curl_malloc(sizeof(struct SessionHandle));
   if(!data)
     /* this is a very serious error */
     return CURLE_OUT_OF_MEMORY;
@@ -272,7 +270,7 @@
 
 #ifdef USE_ARES
   if(ARES_SUCCESS != ares_init(&data->state.areschannel)) {
- free(data);
+ curl_free(data);
     return CURLE_FAILED_INIT;
   }
   /* make sure that all other returns from this function should destroy the
@@ -281,9 +279,9 @@
 
   /* We do some initial setup here, all those fields that can't be just 0 */
 
- data->state.headerbuff=(char*)malloc(HEADERSIZE);
+ data->state.headerbuff=(char*)curl_malloc(HEADERSIZE);
   if(!data->state.headerbuff) {
- free(data); /* free the memory again */
+ curl_free(data); /* free the memory again */
     return CURLE_OUT_OF_MEMORY;
   }
 
@@ -326,11 +324,11 @@
   /* create an array with connection data struct pointers */
   data->state.numconnects = 5; /* hard-coded right now */
   data->state.connects = (struct connectdata **)
- malloc(sizeof(struct connectdata *) * data->state.numconnects);
+ curl_malloc(sizeof(struct connectdata *) * data->state.numconnects);
 
   if(!data->state.connects) {
- free(data->state.headerbuff);
- free(data);
+ curl_free(data->state.headerbuff);
+ curl_free(data);
     return CURLE_OUT_OF_MEMORY;
   }
 
@@ -411,7 +409,7 @@
       if(newconnects) {
         int i;
         newptr= (struct connectdata **)
- realloc(data->state.connects,
+ curl_realloc(data->state.connects,
                   sizeof(struct connectdata *) * newconnects);
         if(!newptr)
           /* we closed a few connections in vain, but so what? */
@@ -428,7 +426,7 @@
       else {
         /* zero makes NO cache at all */
         if(data->state.connects)
- free(data->state.connects);
+ curl_free(data->state.connects);
         data->state.connects=NULL;
         data->state.numconnects=0;
       }
@@ -764,7 +762,7 @@
      */
     if(data->change.url_alloc) {
       /* the already set URL is allocated, free it first! */
- free(data->change.url);
+ curl_free(data->change.url);
       data->change.url_alloc=FALSE;
     }
     data->set.set_url = va_arg(param, char *);
@@ -811,7 +809,7 @@
      * String to set in the HTTP Referer: field.
      */
     if(data->change.referer_alloc) {
- free(data->change.referer);
+ curl_free(data->change.referer);
       data->change.referer_alloc = FALSE;
     }
     data->set.set_referer = va_arg(param, char *);
@@ -838,7 +836,7 @@
        * The already set string is allocated, free that first
        */
       data->change.proxy_alloc=FALSE;;
- free(data->change.proxy);
+ curl_free(data->change.proxy);
     }
     data->set.set_proxy = va_arg(param, char *);
     data->change.proxy = data->set.set_proxy;
@@ -1344,7 +1342,7 @@
    * to free this resource here as well.
    */
   if(conn->bits.rangestringalloc) {
- free(conn->range);
+ curl_free(conn->range);
     conn->bits.rangestringalloc = FALSE;
   }
 
@@ -1419,7 +1417,7 @@
   
   Curl_free_ssl_config(&conn->ssl_config);
 
- free(conn); /* free all the connection oriented data */
+ curl_free(conn); /* free all the connection oriented data */
 
   return CURLE_OK;
 }
@@ -2071,7 +2069,7 @@
      to not have to modify everything at once, we allocate a temporary
      connection data struct and fill in for comparison purposes. */
 
- conn = (struct connectdata *)malloc(sizeof(struct connectdata));
+ conn = (struct connectdata *)curl_malloc(sizeof(struct connectdata));
   if(!conn) {
     *in_connect = NULL; /* clear the pointer */
     return CURLE_OUT_OF_MEMORY;
@@ -2130,12 +2128,12 @@
   if(urllen < LEAST_PATH_ALLOC)
     urllen=LEAST_PATH_ALLOC;
 
- conn->pathbuffer=(char *)malloc(urllen);
+ conn->pathbuffer=(char *)curl_malloc(urllen);
   if(NULL == conn->pathbuffer)
     return CURLE_OUT_OF_MEMORY; /* really bad error */
   conn->path = conn->pathbuffer;
 
- conn->host.rawalloc=(char *)malloc(urllen);
+ conn->host.rawalloc=(char *)curl_malloc(urllen);
   if(NULL == conn->host.rawalloc)
     return CURLE_OUT_OF_MEMORY;
   conn->host.name = conn->host.rawalloc;
@@ -2288,11 +2286,11 @@
            "%" MAX_CURL_PASSWORD_LENGTH_TXT "[^\n]",
            proxyuser, proxypasswd);
 
- conn->proxyuser = strdup(proxyuser);
+ conn->proxyuser = curl_strdup(proxyuser);
     if(!conn->proxyuser)
       return CURLE_OUT_OF_MEMORY;
     
- conn->proxypasswd = strdup(proxypasswd);
+ conn->proxypasswd = curl_strdup(proxypasswd);
     if(!conn->proxypasswd)
       return CURLE_OUT_OF_MEMORY;
   }
@@ -2420,21 +2418,21 @@
                                  proxyuser, proxypasswd))) {
             /* found user and password, rip them out */
             Curl_safefree(conn->proxyuser);
- conn->proxyuser = strdup(proxyuser);
+ conn->proxyuser = curl_strdup(proxyuser);
 
             if(!conn->proxyuser)
               return CURLE_OUT_OF_MEMORY;
             
             Curl_safefree(conn->proxypasswd);
- conn->proxypasswd = strdup(proxypasswd);
+ conn->proxypasswd = curl_strdup(proxypasswd);
 
             if(!conn->proxypasswd)
               return CURLE_OUT_OF_MEMORY;
             
             conn->bits.proxy_user_passwd = TRUE; /* enable it */
 
- ptr = strdup(ptr+1); /* the right side of the @-letter */
- free(proxy); /* free the former data */
+ ptr = curl_strdup(ptr+1); /* the right side of the @-letter */
+ curl_free(proxy); /* free the former data */
             proxy = ptr; /* now use this instead */
           }
 
@@ -2446,7 +2444,7 @@
       } /* if (!nope) - it wasn't specified non-proxy */
     } /* NO_PROXY wasn't specified or '*' */
     if(no_proxy)
- free(no_proxy);
+ curl_free(no_proxy);
   } /* if not using proxy */
 
   /*************************************************************
@@ -2483,7 +2481,7 @@
       /* if it already was in use, we just skip this */
       snprintf(resumerange, sizeof(resumerange), "%" FORMAT_OFF_T "-",
                conn->resume_from);
- conn->range=strdup(resumerange); /* tell ourselves to fetch this range */
+ conn->range=curl_strdup(resumerange); /* tell ourselves to fetch this range */
       conn->bits.rangestringalloc = TRUE; /* mark as allocated */
       conn->bits.use_range = 1; /* switch on range usage */
     }
@@ -2764,7 +2762,7 @@
 
     /* We need to make a duplicate of the proxy so that we can modify the
        string safely. */
- char *proxydup=strdup(data->change.proxy);
+ char *proxydup=curl_strdup(data->change.proxy);
 
     /* We use 'proxyptr' to point to the proxy name from now on... */
     char *proxyptr=proxydup;
@@ -2800,10 +2798,10 @@
     }
 
     /* now, clone the cleaned proxy host name */
- conn->proxy.rawalloc = strdup(proxyptr);
+ conn->proxy.rawalloc = curl_strdup(proxyptr);
     conn->proxy.name = conn->proxy.rawalloc;
 
- free(proxydup); /* free the duplicate pointer and not the modified */
+ curl_free(proxydup); /* free the duplicate pointer and not the modified */
   }
 
   /*************************************************************
@@ -2873,7 +2871,7 @@
           }
           /* if the new name is longer than accepted, then just use
              the unconverted name, it'll be wrong but what the heck */
- free(newname);
+ curl_free(newname);
         }
         if (passwd[0]) {
           /* we have a password found in the URL, decode it! */
@@ -2881,7 +2879,7 @@
           if(strlen(newpasswd) < sizeof(passwd)) {
             strcpy(passwd, newpasswd);
           }
- free(newpasswd);
+ curl_free(newpasswd);
         }
       }
     }
@@ -2919,15 +2917,15 @@
   if ( (conn->protocol & PROT_FTP) &&
        !conn->bits.user_passwd) {
 
- conn->user = strdup(CURL_DEFAULT_USER);
- conn->passwd = strdup(CURL_DEFAULT_PASSWORD);
+ conn->user = curl_strdup(CURL_DEFAULT_USER);
+ conn->passwd = curl_strdup(CURL_DEFAULT_PASSWORD);
 
     /* This is the default password, so DON'T set conn->bits.user_passwd */
   }
   else {
     /* store user + password, zero-length if not set */
- conn->user = strdup(user);
- conn->passwd = strdup(passwd);
+ conn->user = curl_strdup(user);
+ conn->passwd = curl_strdup(passwd);
   }
 
   /*************************************************************
@@ -2960,7 +2958,7 @@
     struct connectdata *old_conn = conn;
 
     if(old_conn->proxy.rawalloc)
- free(old_conn->proxy.rawalloc);
+ curl_free(old_conn->proxy.rawalloc);
 
     /* free the SSL config struct from this connection struct as this was
        allocated in vain and is targeted for destruction */
@@ -2976,9 +2974,9 @@
     /* get the newly set value, not the old one */
     conn->bits.no_body = old_conn->bits.no_body;
 
- free(old_conn->host.rawalloc); /* free the newly allocated name buffer */
+ curl_free(old_conn->host.rawalloc); /* free the newly allocated name buffer */
 
- free(conn->pathbuffer); /* free the newly allocated path pointer */
+ curl_free(conn->pathbuffer); /* free the newly allocated path pointer */
     conn->pathbuffer = old_conn->pathbuffer; /* use the old one */
     conn->path = old_conn->path;
 
@@ -2994,9 +2992,9 @@
     Curl_safefree(old_conn->proxypasswd);
 
     if(old_conn->bits.rangestringalloc)
- free(old_conn->range);
+ curl_free(old_conn->range);
 
- free(old_conn); /* we don't need this anymore */
+ curl_free(old_conn); /* we don't need this anymore */
 
     /*
      * If we're doing a resumed transfer, we need to setup our stuff
@@ -3007,16 +3005,16 @@
       snprintf(resumerange, sizeof(resumerange), "%" FORMAT_OFF_T "-",
                conn->resume_from);
       if (conn->bits.rangestringalloc == TRUE)
- free(conn->range);
+ curl_free(conn->range);
 
       /* tell ourselves to fetch this range */
- conn->range = strdup(resumerange);
+ conn->range = curl_strdup(resumerange);
       conn->bits.use_range = TRUE; /* enable range download */
       conn->bits.rangestringalloc = TRUE; /* mark range string allocated */
     }
     else if (data->set.set_range) {
       /* There is a range, but is not a resume, useful for random ftp access */
- conn->range = strdup(data->set.set_range);
+ conn->range = curl_strdup(data->set.set_range);
       conn->bits.rangestringalloc = TRUE; /* mark range string allocated */
       conn->bits.use_range = TRUE; /* enable range download */
     }
@@ -3347,13 +3345,13 @@
   /* cleanups done even if the connection is re-used */
 
   if(conn->bits.rangestringalloc) {
- free(conn->range);
+ curl_free(conn->range);
     conn->bits.rangestringalloc = FALSE;
   }
 
   /* Cleanup possible redirect junk */
   if(conn->newurl) {
- free(conn->newurl);
+ curl_free(conn->newurl);
     conn->newurl = NULL;
   }
 
@@ -3502,31 +3500,31 @@
   dest->version = source->version;
 
   if(source->CAfile) {
- dest->CAfile = strdup(source->CAfile);
+ dest->CAfile = curl_strdup(source->CAfile);
     if(!dest->CAfile)
       return FALSE;
   }
 
   if(source->CApath) {
- dest->CApath = strdup(source->CApath);
+ dest->CApath = curl_strdup(source->CApath);
     if(!dest->CApath)
       return FALSE;
   }
 
   if(source->cipher_list) {
- dest->cipher_list = strdup(source->cipher_list);
+ dest->cipher_list = curl_strdup(source->cipher_list);
     if(!dest->cipher_list)
       return FALSE;
   }
 
   if(source->egdsocket) {
- dest->egdsocket = strdup(source->egdsocket);
+ dest->egdsocket = curl_strdup(source->egdsocket);
     if(!dest->egdsocket)
       return FALSE;
   }
 
   if(source->random_file) {
- dest->random_file = strdup(source->random_file);
+ dest->random_file = curl_strdup(source->random_file);
     if(!dest->random_file)
       return FALSE;
   }
@@ -3537,18 +3535,18 @@
 void Curl_free_ssl_config(struct ssl_config_data* sslc)
 {
   if(sslc->CAfile)
- free(sslc->CAfile);
+ curl_free(sslc->CAfile);
 
   if(sslc->CApath)
- free(sslc->CApath);
+ curl_free(sslc->CApath);
 
   if(sslc->cipher_list)
- free(sslc->cipher_list);
+ curl_free(sslc->cipher_list);
 
   if(sslc->egdsocket)
- free(sslc->egdsocket);
+ curl_free(sslc->egdsocket);
 
   if(sslc->random_file)
- free(sslc->random_file);
+ curl_free(sslc->random_file);
 }
 
Index: src/getpass.c
===================================================================
RCS file: /repository/curl/src/getpass.c,v
retrieving revision 1.6
diff -u -3 -H -r1.6 getpass.c
--- src/getpass.c 10 Mar 2004 16:03:12 -0000 1.6
+++ src/getpass.c 6 May 2004 07:17:50 -0000
@@ -94,9 +94,7 @@
 #endif
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "../lib/memdebug.h"
-#endif
 
 char *getpass_r(const char *prompt, char *buffer, size_t buflen)
 {
Index: src/homedir.c
===================================================================
RCS file: /repository/curl/src/homedir.c,v
retrieving revision 1.4
diff -u -3 -H -r1.4 homedir.c
--- src/homedir.c 29 Jan 2004 13:54:08 -0000 1.4
+++ src/homedir.c 6 May 2004 07:17:50 -0000
@@ -42,9 +42,7 @@
 
 #include "homedir.h"
 
-#ifdef CURLDEBUG
 #include "../lib/memdebug.h"
-#endif
 
 static
 char *GetEnv(const char *variable, char do_expand)
@@ -81,7 +79,7 @@
   env = getenv(variable);
 #endif
 #endif
- return (env && env[0])?strdup(env):NULL;
+ return (env && env[0])?curl_strdup(env):NULL;
 }
 
 /* return the home directory of the current user as an allocated string */
@@ -102,7 +100,7 @@
      home = pw->pw_dir;
 #endif
      if (home && home[0])
- home = strdup(home);
+ home = curl_strdup(home);
    }
  }
 #endif /* PWD-stuff */
Index: src/main.c
===================================================================
RCS file: /repository/curl/src/main.c,v
retrieving revision 1.261
diff -u -3 -H -r1.261 main.c
--- src/main.c 5 May 2004 07:30:52 -0000 1.261
+++ src/main.c 6 May 2004 07:17:55 -0000
@@ -106,12 +106,10 @@
 #include <curlx.h> /* header from the libcurl directory */
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 /* This is low-level hard-hacking memory leak tracking and similar. Using
    the library level code from this client-side is ugly, but we do this
    anyway for convenience. */
 #include "memdebug.h"
-#endif
 
 #define DEFAULT_MAXREDIRS 50L
 
@@ -179,25 +177,6 @@
 /* Send authentication (user+password) when following
  * locations, even when hostname changed */
 
-#ifndef HAVE_STRDUP
-/* Ultrix doesn't have strdup(), so make a quick clone: */
-char *strdup(char *str)
-{
- int len;
- char *newstr;
-
- len = strlen(str);
- newstr = (char *) malloc((len+1)*sizeof(char));
- if (!newstr)
- return (char *)NULL;
-
- strcpy(newstr,str);
-
- return newstr;
-
-}
-#endif
-
 #ifdef WIN32
 #include <direct.h>
 #define F_OK 0
@@ -521,9 +500,9 @@
                    char *value)
 {
   if(*string)
- free(*string);
+ curl_free(*string);
   if(value)
- *string = strdup(value);
+ *string = curl_strdup(value);
   else
     *string = NULL;
 }
@@ -546,9 +525,9 @@
         *ptr=0;
       stringlen=strlen(buffer);
       if(string)
- string = realloc(string, len+stringlen+1);
+ string = curl_realloc(string, len+stringlen+1);
       else
- string = malloc(stringlen+1);
+ string = curl_malloc(stringlen+1);
 
       strcpy(string+len, buffer);
 
@@ -571,14 +550,14 @@
   if(file) {
     while((len = fread(buffer, 1, sizeof(buffer), file))) {
       if(string) {
- newstring = realloc(string, len+stringlen);
+ newstring = curl_realloc(string, len+stringlen);
         if(newstring)
           string = newstring;
         else
           break; /* no more strings attached! :-) */
       }
       else
- string = malloc(len);
+ string = curl_malloc(len);
       memcpy(&string[stringlen], buffer, len);
       stringlen+=len;
     }
@@ -597,12 +576,12 @@
   while(node) {
     next = node->next;
     if(node->url)
- free(node->url);
+ curl_free(node->url);
     if(node->outfile)
- free(node->outfile);
+ curl_free(node->outfile);
     if(node->infile)
- free(node->infile);
- free(node);
+ curl_free(node->infile);
+ curl_free(node);
 
     node = next; /* GOTO next */
   }
@@ -610,7 +589,7 @@
 
 static struct getout *new_getout(struct Configurable *config)
 {
- struct getout *node =malloc(sizeof(struct getout));
+ struct getout *node =curl_malloc(sizeof(struct getout));
   struct getout *last= config->url_last;
   if(node) {
     /* clear the struct */
@@ -648,7 +627,7 @@
   struct multi_files *multi;
   struct multi_files *multi_type = NULL;
   struct multi_files *multi_name = NULL;
- multi = (struct multi_files *)malloc(sizeof(struct multi_files));
+ multi = (struct multi_files *)curl_malloc(sizeof(struct multi_files));
   if (multi) {
     memset(multi, 0, sizeof(struct multi_files));
     multi->form.option = CURLFORM_FILE;
@@ -661,7 +640,7 @@
     *multi_start = multi;
 
   if (type_name) {
- multi_type = (struct multi_files *)malloc(sizeof(struct multi_files));
+ multi_type = (struct multi_files *)curl_malloc(sizeof(struct multi_files));
     if (multi_type) {
       memset(multi_type, 0, sizeof(struct multi_files));
       multi_type->form.option = CURLFORM_CONTENTTYPE;
@@ -671,12 +650,12 @@
       multi = multi_type;
     }
     else {
- free (multi);
+ curl_free (multi);
       return NULL;
     }
   }
   if (show_filename) {
- multi_name = (struct multi_files *)malloc(sizeof(struct multi_files));
+ multi_name = (struct multi_files *)curl_malloc(sizeof(struct multi_files));
     if (multi_name) {
       memset(multi_name, 0, sizeof(struct multi_files));
       multi_name->form.option = CURLFORM_FILENAME;
@@ -686,7 +665,7 @@
       multi = multi_name;
     }
     else {
- free (multi);
+ curl_free (multi);
       return NULL;
     }
   }
@@ -707,7 +686,7 @@
   while (multi_start) {
     multi = multi_start;
     multi_start = multi_start->next;
- free (multi);
+ curl_free (multi);
   }
 }
 
@@ -768,7 +747,7 @@
     /* the input was using the correct format */
     
     /* Allocate the contents */
- contents = strdup(contp+1);
+ contents = curl_strdup(contp+1);
     contp = contents;
 
     if('@' == contp[0]) {
@@ -821,7 +800,7 @@
               if(2 != sscanf(type, "%127[^/]/%127[^;,\n]",
                              major, minor)) {
                 fprintf(stderr, "Illegally formatted content-type field!\n");
- free(contents);
+ curl_free(contents);
                 FreeMultiInfo (multi_start);
                 return 2; /* illegal content-type syntax! */
               }
@@ -866,7 +845,7 @@
         if (!AddMultiFiles (contp, type, filename, &multi_start,
                             &multi_current)) {
           fprintf(stderr, "Error building form post!\n");
- free(contents);
+ curl_free(contents);
           FreeMultiInfo (multi_start);
           return 3;
         }
@@ -884,11 +863,11 @@
           ++count;
         }
         forms =
- (struct curl_forms *)malloc((count+1)*sizeof(struct curl_forms));
+ (struct curl_forms *)curl_malloc((count+1)*sizeof(struct curl_forms));
         if (!forms)
         {
           fprintf(stderr, "Error building form post!\n");
- free(contents);
+ curl_free(contents);
           FreeMultiInfo (multi_start);
           return 4;
         }
@@ -903,11 +882,11 @@
                          CURLFORM_COPYNAME, name,
                          CURLFORM_ARRAY, forms, CURLFORM_END) != 0) {
           fprintf(stderr, "curl_formadd failed!\n");
- free(forms);
- free(contents);
+ curl_free(forms);
+ curl_free(contents);
           return 5;
         }
- free(forms);
+ curl_free(forms);
       }
     }
     else {
@@ -916,7 +895,7 @@
                          CURLFORM_COPYNAME, name,
                          CURLFORM_FILECONTENT, contp+1, CURLFORM_END) != 0) {
           fprintf(stderr, "curl_formadd failed!\n");
- free(contents);
+ curl_free(contents);
           return 6;
         }
       }
@@ -925,7 +904,7 @@
                          CURLFORM_COPYNAME, name,
                          CURLFORM_COPYCONTENTS, contp, CURLFORM_END) != 0) {
           fprintf(stderr, "curl_formadd failed!\n");
- free(contents);
+ curl_free(contents);
           return 7;
         }
       }
@@ -936,7 +915,7 @@
     fprintf(stderr, "Illegally formatted input field!\n");
     return 1;
   }
- free(contents);
+ curl_free(contents);
   return 0;
 }
 
@@ -1068,7 +1047,7 @@
     passwdlen = strlen(passwd);
 
     /* extend the allocated memory area to fit the password too */
- passptr = realloc(*userpwd,
+ passptr = curl_realloc(*userpwd,
                       passwdlen + 1 + /* an extra for the colon */
                       userlen + 1); /* an extra for the zero */
 
@@ -1461,7 +1440,7 @@
         break;
       case 'b': /* --ftp-pasv */
         if(config->ftpport)
- free(config->ftpport);
+ curl_free(config->ftpport);
         config->ftpport = NULL;
         break;
       case 'c': /* --socks specifies a socks5 proxy to use */
@@ -1576,8 +1555,8 @@
              with a separating &-letter */
           char *oldpost=config->postfields;
           config->postfields=aprintf("%s&%s", oldpost, postdata);
- free(oldpost);
- free(postdata);
+ curl_free(oldpost);
+ curl_free(postdata);
         }
         else
           config->postfields=postdata;
@@ -2050,7 +2029,7 @@
 
         filename = filebuffer;
       }
- free(home); /* we've used it, now free it */
+ curl_free(home); /* we've used it, now free it */
     }
     
 # else /* AmigaOS */
@@ -2092,7 +2071,7 @@
       case '\n':
       case '*':
       case '\0':
- free(aline);
+ curl_free(aline);
         continue;
       }
 
@@ -2118,7 +2097,7 @@
         char *ptr;
         /* quoted parameter, do the qoute dance */
         line++;
- param=strdup(line); /* parameter */
+ param=curl_strdup(line); /* parameter */
         alloced_param=TRUE;
 
         ptr=param;
@@ -2164,7 +2143,7 @@
         /* do this so getparameter can check for required parameters.
            Otherwise it always thinks there's a parameter. */
         if (alloced_param)
- free(param);
+ curl_free(param);
         param = NULL;
       }
 
@@ -2191,11 +2170,11 @@
 
       if(alloced_param)
       {
- free(param);
+ curl_free(param);
         param = NULL;
       }
 
- free(aline);
+ curl_free(aline);
     }
     if(file != stdin)
       fclose(file);
@@ -2576,41 +2555,41 @@
 static void free_config_fields(struct Configurable *config)
 {
   if(config->random_file)
- free(config->random_file);
+ curl_free(config->random_file);
   if(config->egd_file)
- free(config->egd_file);
+ curl_free(config->egd_file);
   if(config->userpwd)
- free(config->userpwd);
+ curl_free(config->userpwd);
   if(config->postfields)
- free(config->postfields);
+ curl_free(config->postfields);
   if(config->proxy)
- free(config->proxy);
+ curl_free(config->proxy);
   if(config->proxyuserpwd)
- free(config->proxyuserpwd);
+ curl_free(config->proxyuserpwd);
   if(config->cookie)
- free(config->cookie);
+ curl_free(config->cookie);
   if(config->cookiefile)
- free(config->cookiefile);
+ curl_free(config->cookiefile);
   if(config->krb4level)
- free(config->krb4level);
+ curl_free(config->krb4level);
   if(config->headerfile)
- free(config->headerfile);
+ curl_free(config->headerfile);
   if(config->ftpport)
- free(config->ftpport);
+ curl_free(config->ftpport);
   if(config->range)
- free(config->range);
+ curl_free(config->range);
   if(config->customrequest)
- free(config->customrequest);
+ curl_free(config->customrequest);
   if(config->writeout)
- free(config->writeout);
+ curl_free(config->writeout);
   if(config->httppost)
     curl_formfree(config->httppost);
   if(config->cacert)
- free(config->cacert);
+ curl_free(config->cacert);
   if(config->capath)
- free(config->capath);
+ curl_free(config->capath);
   if(config->cookiejar)
- free(config->cookiejar);
+ curl_free(config->cookiejar);
 
   curl_slist_free_all(config->quote); /* checks for config->quote == NULL */
   curl_slist_free_all(config->postquote); /* */
@@ -2636,7 +2615,7 @@
   if(curlinfo->features & CURL_VERSION_SSL) {
     DWORD buflen;
     char *ptr = NULL;
- char *retval = (char *) malloc(sizeof (TCHAR) * (MAX_PATH + 1));
+ char *retval = (char *) curl_malloc(sizeof (TCHAR) * (MAX_PATH + 1));
     if (!retval)
       return;
     retval[0] = '\0';
@@ -2644,7 +2623,7 @@
     if (buflen > 0) {
       GetStr(&config->cacert, retval);
     }
- free(retval);
+ curl_free(retval);
   }
 }
 
@@ -2822,12 +2801,12 @@
   if (config->postfields) {
     if (config->use_httpget) {
       /* Use the postfields data for a http get */
- httpgetfields = strdup(config->postfields);
- free(config->postfields);
+ httpgetfields = curl_strdup(config->postfields);
+ curl_free(config->postfields);
       config->postfields = NULL;
       if(SetHTTPrequest((config->conf&CONF_NOBODY?HTTPREQ_HEAD:HTTPREQ_GET),
                         &config->httpreq)) {
- free(httpgetfields);
+ curl_free(httpgetfields);
         return PARAM_BAD_USE;
       }
     }
@@ -2876,11 +2855,11 @@
     if(NULL == url) {
       /* This node had no URL, skip it and continue to the next */
       if(urlnode->outfile)
- free(urlnode->outfile);
+ curl_free(urlnode->outfile);
     
       /* move on to the next URL */
       nextnode=urlnode->next;
- free(urlnode); /* free the node */
+ curl_free(urlnode); /* free the node */
       urlnode = nextnode;
       continue; /* next please */
     }
@@ -2890,7 +2869,7 @@
     outs.config = config;
 
     /* save outfile pattern before expansion */
- outfiles = urlnode->outfile?strdup(urlnode->outfile):NULL;
+ outfiles = urlnode->outfile?curl_strdup(urlnode->outfile):NULL;
 
     infiles = urlnode->infile;
 
@@ -2911,7 +2890,7 @@
         (!up && !infiles) ||
           (uploadfile = inglob?
            glob_next_url(inglob):
- (!up?strdup(infiles):NULL));
+ (!up?curl_strdup(infiles):NULL));
         up++) {
       uploadfilesize=-1;
 
@@ -2933,10 +2912,10 @@
 
       /* Here's looping around each globbed URL */
       for(i = 0;
- (url = urls?glob_next_url(urls):(i?NULL:strdup(url)));
+ (url = urls?glob_next_url(urls):(i?NULL:curl_strdup(url)));
           i++) {
         char *outfile;
- outfile = outfiles?strdup(outfiles):NULL;
+ outfile = outfiles?curl_strdup(outfiles):NULL;
         
         if((urlnode->flags&GETOUT_USEREMOTE) ||
            (outfile && !curlx_strequal("-", outfile)) ) {
@@ -2958,12 +2937,12 @@
             if(pc) {
               /* duplicate the string beyond the slash */
               pc++;
- outfile = *pc ? strdup(pc): NULL;
+ outfile = *pc ? curl_strdup(pc): NULL;
             }
             if(!outfile || !*outfile) {
               helpf("Remote file name has no length!\n");
               res = CURLE_WRITE_ERROR;
- free(url);
+ curl_free(url);
               break;
             }
 #if defined(__DJGPP__)
@@ -2973,8 +2952,8 @@
               char file1 [PATH_MAX];
 
               strcpy(file1, msdosify(outfile));
- free (outfile);
- outfile = strdup (rename_if_dos_device_name(file1));
+ curl_free (outfile);
+ outfile = curl_strdup (rename_if_dos_device_name(file1));
             }
 #endif /* __DJGPP__ */
           }
@@ -2982,11 +2961,11 @@
             /* fill '#1' ... '#9' terms from URL pattern */
             char *storefile = outfile;
             outfile = glob_match_url(storefile, urls);
- free(storefile);
+ curl_free(storefile);
             if(!outfile) {
               /* bad globbing */
               fprintf(stderr, "bad output glob!\n");
- free(url);
+ curl_free(url);
               res = CURLE_FAILED_INIT;
               break;
             }
@@ -3065,7 +3044,7 @@
 
             if(filep) {
 
- urlbuffer=(char *)malloc(strlen(url) + strlen(filep) + 3);
+ urlbuffer=(char *)curl_malloc(strlen(url) + strlen(filep) + 3);
               if(!urlbuffer) {
                 helpf("out of memory\n");
                 return CURLE_OUT_OF_MEMORY;
@@ -3079,7 +3058,7 @@
             
               curl_free(filep);
 
- free(url);
+ curl_free(url);
               url = urlbuffer; /* use our new URL instead! */
             }
           }
@@ -3147,7 +3126,7 @@
           /*
            * Then append ? followed by the get fields to the url.
            */
- urlbuffer=(char *)malloc(strlen(url) + strlen(httpgetfields) + 2);
+ urlbuffer=(char *)curl_malloc(strlen(url) + strlen(httpgetfields) + 2);
           if(!urlbuffer) {
             helpf("out of memory\n");
             return CURLE_OUT_OF_MEMORY;
@@ -3160,7 +3139,7 @@
             */
             sprintf(urlbuffer, "%s/?%s", url, httpgetfields);
  
- free(url); /* free previous URL */
+ curl_free(url); /* free previous URL */
           url = urlbuffer; /* use our new URL instead! */
         }
 
@@ -3462,13 +3441,13 @@
           fclose(headerfilep);
       
         if (httpgetfields)
- free(httpgetfields);
+ curl_free(httpgetfields);
 
         if(url)
- free(url);
+ curl_free(url);
 
         if(outfile)
- free(outfile);
+ curl_free(outfile);
 
         if(infdfopen)
           fclose(infd);
@@ -3480,7 +3459,7 @@
         glob_cleanup(urls);
      
       if(uploadfile)
- free(uploadfile);
+ curl_free(uploadfile);
  
     } /* loop to the next globbed upload file */
 
@@ -3488,19 +3467,19 @@
       glob_cleanup(inglob);
 
     if(outfiles)
- free(outfiles);
+ curl_free(outfiles);
 
     /* empty this urlnode struct */
     if(urlnode->url)
- free(urlnode->url);
+ curl_free(urlnode->url);
     if(urlnode->outfile)
- free(urlnode->outfile);
+ curl_free(urlnode->outfile);
     if(urlnode->infile)
- free(urlnode->infile);
+ curl_free(urlnode->infile);
     
     /* move on to the next URL */
     nextnode=urlnode->next;
- free(urlnode); /* free the node */
+ curl_free(urlnode); /* free the node */
     urlnode = nextnode;
 
   } /* while-loop through all URLs */
@@ -3512,7 +3491,7 @@
     fclose(config->trace_stream);
 
   if(allocuseragent)
- free(config->useragent);
+ curl_free(config->useragent);
 
   /* cleanup the curl handle! */
   curl_easy_cleanup(curl);
@@ -3555,9 +3534,9 @@
      if (NULL == fgets(buf, sizeof(buf), fp))
        break;
      if (NULL == retval)
- retval = strdup(buf);
+ retval = curl_strdup(buf);
      else {
- if (NULL == (retval = realloc(retval,
+ if (NULL == (retval = curl_realloc(retval,
                                      strlen(retval) + strlen(buf) + 1)))
          break;
        strcat(retval, buf);
@@ -3585,8 +3564,8 @@
   char *dirbuildup;
   int result=0;
   
- outdup = strdup(outfile);
- dirbuildup = malloc(sizeof(char) * strlen(outfile));
+ outdup = curl_strdup(outfile);
+ dirbuildup = curl_malloc(sizeof(char) * strlen(outfile));
   if(!dirbuildup)
     return -1;
   dirbuildup[0] = '\0';
@@ -3650,8 +3629,8 @@
     }
     tempdir = tempdir2;
   }
- free(dirbuildup);
- free(outdup);
+ curl_free(dirbuildup);
+ curl_free(outdup);
 
   return result; /* 0 is fine, -1 is badness */
 }
Index: src/urlglob.c
===================================================================
RCS file: /repository/curl/src/urlglob.c,v
retrieving revision 1.33
diff -u -3 -H -r1.33 urlglob.c
--- src/urlglob.c 6 Apr 2004 07:48:29 -0000 1.33
+++ src/urlglob.c 6 May 2004 07:17:57 -0000
@@ -35,10 +35,7 @@
 
 #include "urlglob.h"
 
-
-#ifdef CURLDEBUG
 #include "../lib/memdebug.h"
-#endif
 
 typedef enum {
   GLOB_OK,
@@ -70,7 +67,7 @@
   pat->type = UPTSet;
   pat->content.Set.size = 0;
   pat->content.Set.ptr_s = 0;
- pat->content.Set.elements = (char**)malloc(0);
+ pat->content.Set.elements = (char**)curl_malloc(0);
   ++glob->size;
 
   while (1) {
@@ -90,14 +87,14 @@
     case '}': /* set element completed */
       *buf = '\0';
       pat->content.Set.elements =
- realloc(pat->content.Set.elements,
+ curl_realloc(pat->content.Set.elements,
                 (pat->content.Set.size + 1) * sizeof(char*));
       if (!pat->content.Set.elements) {
         snprintf(glob->errormsg, sizeof(glob->errormsg), "out of memory");
         return GLOB_ERROR;
       }
       pat->content.Set.elements[pat->content.Set.size] =
- strdup(glob->glob_buffer);
+ curl_strdup(glob->glob_buffer);
       ++pat->content.Set.size;
 
       if (*pattern == '}') {
@@ -257,7 +254,7 @@
   *buf = '\0';
   litindex = glob->size / 2;
   /* literals 0,1,2,... correspond to size=0,2,4,... */
- glob->literal[litindex] = strdup(glob->glob_buffer);
+ glob->literal[litindex] = curl_strdup(glob->glob_buffer);
   if(!glob->literal[litindex])
     return GLOB_ERROR;
   ++glob->size;
@@ -279,7 +276,7 @@
 
   if(GLOB_OK != res)
     /* free that strdup'ed string again */
- free(glob->literal[litindex]);
+ curl_free(glob->literal[litindex]);
 
   return res; /* something got wrong */
 }
@@ -292,15 +289,15 @@
    */
   URLGlob *glob_expand;
   int amount;
- char *glob_buffer=(char *)malloc(strlen(url)+1);
+ char *glob_buffer=(char *)curl_malloc(strlen(url)+1);
 
   *glob = NULL;
   if(NULL == glob_buffer)
     return CURLE_OUT_OF_MEMORY;
 
- glob_expand = (URLGlob*)malloc(sizeof(URLGlob));
+ glob_expand = (URLGlob*)curl_malloc(sizeof(URLGlob));
   if(NULL == glob_expand) {
- free(glob_buffer);
+ curl_free(glob_buffer);
     return CURLE_OUT_OF_MEMORY;
   }
   glob_expand->size = 0;
@@ -316,8 +313,8 @@
               CURLE_URL_MALFORMAT, glob_expand->errormsg);
     }
     /* it failed, we cleanup */
- free(glob_buffer);
- free(glob_expand);
+ curl_free(glob_buffer);
+ curl_free(glob_expand);
     glob_expand = NULL;
     *urlnum = 1;
     return CURLE_URL_MALFORMAT;
@@ -333,21 +330,21 @@
 
   for (i = glob->size - 1; i >= 0; --i) {
     if (!(i & 1)) { /* even indexes contain literals */
- free(glob->literal[i/2]);
+ curl_free(glob->literal[i/2]);
     }
     else { /* odd indexes contain sets or ranges */
       if (glob->pattern[i/2].type == UPTSet) {
         for (elem = glob->pattern[i/2].content.Set.size - 1;
              elem >= 0;
              --elem) {
- free(glob->pattern[i/2].content.Set.elements[elem]);
+ curl_free(glob->pattern[i/2].content.Set.elements[elem]);
         }
- free(glob->pattern[i/2].content.Set.elements);
+ curl_free(glob->pattern[i/2].content.Set.elements);
       }
     }
   }
- free(glob->glob_buffer);
- free(glob);
+ curl_free(glob->glob_buffer);
+ curl_free(glob);
 }
 
 char *glob_next_url(URLGlob *glob)
@@ -425,7 +422,7 @@
     }
   }
   *buf = '\0';
- return strdup(glob->glob_buffer);
+ return curl_strdup(glob->glob_buffer);
 }
 
 char *glob_match_url(char *filename, URLGlob *glob)
@@ -442,7 +439,7 @@
    * we need to realloc in case of need.
    */
   allocsize=strlen(filename);
- target = malloc(allocsize);
+ target = curl_malloc(allocsize);
   if(NULL == target)
     return NULL; /* major failure */
 
@@ -477,7 +474,7 @@
         default:
           printf("internal error: invalid pattern type (%d)\n",
                  (int)pat.type);
- free(target);
+ curl_free(target);
           return NULL;
         }
       }
@@ -489,9 +486,9 @@
     if(appendlen + stringlen >= allocsize) {
       char *newstr;
       allocsize = (appendlen + stringlen)*2;
- newstr=realloc(target, allocsize);
+ newstr=curl_realloc(target, allocsize);
       if(NULL ==newstr) {
- free(target);
+ curl_free(target);
         return NULL;
       }
       target=newstr;
Received on 2004-05-07