diff --git a/CHANGES b/CHANGES
index a17d3c3a60ac6194b25085e7e27c6c820bb13710..5db781a37be78437108ffb22aec2056e09d2429a 100644
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,10 @@
                                   Changelog
 
 Daniel (11 May 2004)
+- Seshubabu Pasam provided a patch that introduces curl_global_init_mem() -
+  like normal curl_global_init() but allows the app to replace all memory
+  functions with its own set. I modified it slightly.
+
 - Based on Luca Alteas' comments, I modified the curllib.dsp generation code.
 
 Daniel (10 May 2004)
diff --git a/RELEASE-NOTES b/RELEASE-NOTES
index a5dd6027523727f5697e203b028e07a7dec418d3..8decfda8ae418bf0972b4381a8a61c2f3c0a2ce9 100644
--- a/RELEASE-NOTES
+++ b/RELEASE-NOTES
@@ -8,10 +8,12 @@ Curl and libcurl 7.12.0.
 
 This release includes the following changes:
 
+ o added curl_global_init_mem()
+ o removed curl_formparse()
  o the MSVC project file in the release archive is automatically built
  o curl --proxy-digest is a new command line option
  o the Windows version of libcurl can use wldap32.dll for LDAP
- o curl_easy_strerror(), curl_multi_strerror() and curl_share_strerror()
+ o added curl_easy_strerror(), curl_multi_strerror() and curl_share_strerror()
  o IPv6-enabled Windows hosts now resolves names threaded/asynch as well
  o configure --with-libidn can be used to point out the root dir of a libidn
    installation for curl to use, then libcurl can resolve and use IDNA names
diff --git a/TODO-RELEASE b/TODO-RELEASE
index 07806b713acb843b40b0bb37d41c3cb782af6cf8..0f25d2eef558608e9ee1890883fe77c2d58f966f 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -5,6 +5,3 @@ Issues not sorted in any particular order.
 
 To get fixed in 7.12.0 (planned release: June 2004)
 ======================
-
-33. Add a function to replace the malloc-calls within libcurl.
-    Low prio. Seshubabu Pasam works on this?
diff --git a/docs/libcurl/Makefile.am b/docs/libcurl/Makefile.am
index eff5e51d996f3de0760e769e3c8cde72fa6fa0d2..81ef28f86f739db4097196f2672a587dbb112409 100644
--- a/docs/libcurl/Makefile.am
+++ b/docs/libcurl/Makefile.am
@@ -15,7 +15,7 @@ man_MANS = curl_easy_cleanup.3 curl_easy_getinfo.3 curl_easy_init.3	\
  curl_multi_perform.3 curl_multi_remove_handle.3 curl_share_cleanup.3	\
  curl_share_init.3 curl_share_setopt.3 libcurl.3 libcurl-easy.3		\
  libcurl-multi.3 libcurl-share.3 libcurl-errors.3 curl_easy_strerror.3	\
- curl_multi_strerror.3 curl_share_strerror.3
+ curl_multi_strerror.3 curl_share_strerror.3 curl_global_init_mem.3
 
 HTMLPAGES = curl_easy_cleanup.html curl_easy_getinfo.html		\
  curl_easy_init.html curl_easy_perform.html curl_easy_setopt.html	\
@@ -30,7 +30,7 @@ HTMLPAGES = curl_easy_cleanup.html curl_easy_getinfo.html		\
  curl_share_cleanup.html curl_share_init.html curl_share_setopt.html	\
  libcurl.html libcurl-multi.html libcurl-easy.html libcurl-share.html	\
  libcurl-errors.html curl_easy_strerror.html curl_multi_strerror.html	\
- curl_share_strerror.html
+ curl_share_strerror.html curl_global_init_mem.html
 
 PDFPAGES = curl_easy_cleanup.pdf curl_easy_getinfo.pdf			\
  curl_easy_init.pdf curl_easy_perform.pdf curl_easy_setopt.pdf		\
@@ -45,7 +45,7 @@ PDFPAGES = curl_easy_cleanup.pdf curl_easy_getinfo.pdf			\
  curl_share_init.pdf curl_share_setopt.pdf libcurl.pdf			\
  libcurl-multi.pdf libcurl-easy.pdf libcurl-share.pdf			\
  libcurl-errors.pdf curl_easy_strerror.pdf curl_multi_strerror.pdf	\
- curl_share_strerror.pdf
+ curl_share_strerror.pdf curl_global_init_mem.pdf
 
 CLEANFILES = $(HTMLPAGES) $(PDFPAGES)
 
diff --git a/docs/libcurl/curl_global_init.3 b/docs/libcurl/curl_global_init.3
index 04a0b02386424e56dc151726b0b6ea8bb3e2de3e..b408850ad8087412724d856e84d39933e8e9b092 100644
--- a/docs/libcurl/curl_global_init.3
+++ b/docs/libcurl/curl_global_init.3
@@ -2,7 +2,7 @@
 .\" nroff -man [file]
 .\" $Id$
 .\"
-.TH curl_global_init 3 "13 Nov 2001" "libcurl 7.9.1" "libcurl Manual"
+.TH curl_global_init 3 "11 May 2004" "libcurl 7.12" "libcurl Manual"
 .SH NAME
 curl_global_init - Global libcurl initialisation
 .SH SYNOPSIS
@@ -42,6 +42,5 @@ Initialise nothing extra. This sets no bit.
 If this function returns non-zero, something went wrong and you cannot use the
 other curl functions.
 .SH "SEE ALSO"
+.BR curl_global_init_mem "(3), "
 .BR curl_global_cleanup "(3), "
-
-
diff --git a/include/curl/curl.h b/include/curl/curl.h
index a0ef1a3c6f203c1e6dedb595f29d1268a73d5b50..5f85ffff6c5f9e7d12ca5abd1d728550a228773a 100644
--- a/include/curl/curl.h
+++ b/include/curl/curl.h
@@ -154,6 +154,18 @@ typedef int (*curl_passwd_callback)(void *clientp,
                                     char *buffer,
                                     int buflen);
 
+/*
+ * The following typedef's are signatures of malloc, free, realloc, strdup and
+ * calloc respectively.  Function pointers of these types can be passed to the
+ * curl_global_init_mem() function to set user defined memory management
+ * callback routines.
+ */
+typedef void *(*curl_malloc_callback)(size_t size);
+typedef void (*curl_free_callback)(void *ptr);
+typedef void *(*curl_realloc_callback)(void *ptr, size_t size);
+typedef char *(*curl_strdup_callback)(const char *str);
+typedef void *(*curl_calloc_callback)(size_t nmemb, size_t size);
+
 /* the kind of data that is passed to information_callback*/
 typedef enum {
   CURLINFO_TEXT = 0,
@@ -1012,6 +1024,26 @@ void curl_free(void *p);
  */
 CURLcode curl_global_init(long flags);
 
+/*
+ * NAME curl_global_init_mem()
+ *
+ * DESCRIPTION
+ *
+ * curl_global_init() or curl_global_init_mem() should be invoked exactly once
+ * for each application that uses libcurl.  This function can be used to
+ * initialize libcurl and 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 library etc.  User registered
+ * callback routines with be invoked by this library instead of the system
+ * memory management routines like malloc, free etc.
+ */
+CURLcode curl_global_init_mem(long flags,
+                              curl_malloc_callback m,
+                              curl_free_callback f,
+                              curl_realloc_callback r,
+                              curl_strdup_callback s,
+                              curl_calloc_callback c);
+
 /*
  * NAME curl_global_cleanup()
  *
diff --git a/lib/Makefile.am b/lib/Makefile.am
index d9038f7d554b852fe6cba5a46a6c9378f71096c4..d1dc1910f27b225a6cc25681f1986ed137b18fad 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -91,8 +91,8 @@ HHEADERS = arpa_telnet.h netrc.h file.h timeval.h base64.h hostip.h	\
   telnet.h getinfo.h strequal.h security.h krb4.h memdebug.h		\
   inet_ntoa_r.h http_chunks.h strtok.h connect.h llist.h hash.h		\
   content_encoding.h share.h md5.h http_digest.h http_negotiate.h	\
-  http_ntlm.hca-bundle.h inet_pton.h strtoofft.h strerror.h		\
-  inet_ntop.h curlx.h
+  http_ntlm.h ca-bundle.h inet_pton.h strtoofft.h strerror.h		\
+  inet_ntop.h curlx.h memory.h
 
 CSOURCES = file.c timeval.c base64.c hostip.c progress.c formdata.c	\
   cookie.c http.c sendf.c ftp.c url.c dict.c if2ip.c speedcheck.c	\
diff --git a/lib/base64.c b/lib/base64.c
index 4af1d72e7668885cfe240e3a1a618c7328087a46..70e5e5cc241242875a5e3144ab03ebb06a427911 100644
--- a/lib/base64.c
+++ b/lib/base64.c
@@ -41,10 +41,11 @@
 #include <curl/mprintf.h>
 
 #include "base64.h"
+#include "memory.h"
 
-#ifdef CURLDEBUG
+/* include memdebug.h last */
 #include "memdebug.h"
-#endif
+
 
 static void decodeQuantum(unsigned char *dest, const char *src)
 {
diff --git a/lib/connect.c b/lib/connect.c
index c7dee3ce2d7eba5d94d02b40caad83816edb28af..0eec75a483402c878e0b8779dceed88808495fbb 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -96,11 +96,10 @@
 #include "if2ip.h"
 #include "strerror.h"
 #include "connect.h"
+#include "memory.h"
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 static bool verifyconnect(curl_socket_t sockfd);
 
diff --git a/lib/content_encoding.c b/lib/content_encoding.c
index a36bba7786e4c35d1dda5e16d3d0bfc2a77b5b58..2a0aaf4021e19ec7d4b44c209bc2d2b9364b51b8 100644
--- a/lib/content_encoding.c
+++ b/lib/content_encoding.c
@@ -32,6 +32,9 @@
 #include <curl/curl.h>
 #include "sendf.h"
 #include "content_encoding.h"
+#include "memory.h"
+
+#include "memdebug.h"
 
 #define DSIZ 0x10000             /* buffer size for decompressed data */
 
diff --git a/lib/cookie.c b/lib/cookie.c
index 41f14011ff7b095e536a9fe9f35101dd3dc6b1b1..4e5818c7202a0c37201a5a73afefdee50fe9394c 100644
--- a/lib/cookie.c
+++ b/lib/cookie.c
@@ -92,6 +92,7 @@ Example set of cookies:
 #include "strequal.h"
 #include "strtok.h"
 #include "sendf.h"
+#include "memory.h"
 
 /* The last #include file should be: */
 #ifdef CURLDEBUG
diff --git a/lib/easy.c b/lib/easy.c
index c04f01e2afcca4b589b26fc76579cac5d5e749fc..c162ef5314b3c1761158ac4280ec14591d6aaf86 100644
--- a/lib/easy.c
+++ b/lib/easy.c
@@ -76,14 +76,13 @@
 #include "getinfo.h"
 #include "hostip.h"
 #include "share.h"
+#include "memory.h"
 
 #define _MPRINTF_REPLACE /* use our functions only */
 #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
@@ -164,6 +163,16 @@ static void idna_init (void)
 static unsigned int  initialized = 0;
 static long          init_flags  = 0;
 
+/*
+ * If a memory-using function (like curl_getenv) is used before
+ * curl_global_init() is called, we need to have these pointers set already.
+ */
+curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc;
+curl_free_callback Curl_cfree = (curl_free_callback)free;
+curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc;
+curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)strdup;
+curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
+
 /**
  * curl_global_init() globally initializes cURL given a bitwise set of the
  * different features of what to initialize.
@@ -173,6 +182,13 @@ CURLcode curl_global_init(long flags)
   if (initialized)
     return CURLE_OK;
 
+  /* Setup the default memory functions here (again) */
+  Curl_cmalloc = (curl_malloc_callback)malloc;
+  Curl_cfree = (curl_free_callback)free;
+  Curl_crealloc = (curl_realloc_callback)realloc;
+  Curl_cstrdup = (curl_strdup_callback)strdup;
+  Curl_ccalloc = (curl_calloc_callback)calloc;
+
   if (flags & CURL_GLOBAL_SSL)
     Curl_SSL_init();
 
@@ -195,6 +211,37 @@ CURLcode curl_global_init(long flags)
   return CURLE_OK;
 }
 
+/*
+ * curl_global_init_mem() globally initializes cURL and also registers the
+ * user provided callback routines.
+ */
+CURLcode curl_global_init_mem(long flags, curl_malloc_callback m,
+                              curl_free_callback f, curl_realloc_callback r,
+                              curl_strdup_callback s, curl_calloc_callback c)
+{
+  CURLcode code = CURLE_OK;
+
+  /* Invalid input, return immediately */
+  if (!m || !f || !r || !s || !c)
+    return CURLE_FAILED_INIT;
+
+  /* Already initialized, don't do it again */
+  if ( initialized )
+    return CURLE_OK;
+
+  /* Call the actual init function first */
+  code = curl_global_init(flags);
+  if (code == CURLE_OK) {
+    Curl_cmalloc = m;
+    Curl_cfree = f;
+    Curl_cstrdup = s;
+    Curl_crealloc = r;
+    Curl_ccalloc = c;
+  }
+
+  return code;
+}
+
 /**
  * curl_global_cleanup() globally cleanups cURL, uses the value of
  * "init_flags" to determine what needs to be cleaned up and what doesn't.
diff --git a/lib/escape.c b/lib/escape.c
index 23c3821fa3d9a7f48f968a1acfb0df98c307ac59..b233600af75fa266b58901b8130a06c90c213d80 100644
--- a/lib/escape.c
+++ b/lib/escape.c
@@ -31,11 +31,10 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include "memory.h"
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 char *curl_escape(const char *string, int length)
 {
diff --git a/lib/file.c b/lib/file.c
index 004718cd4a88062f6c5cf429ac781b5216f38b7d..0edd3d972f76ff08685b60f3f3f02c378361a129 100644
--- a/lib/file.c
+++ b/lib/file.c
@@ -73,7 +73,6 @@
 #include <fcntl.h>
 #endif
 
-
 #endif
 
 #include "urldata.h"
@@ -85,14 +84,13 @@
 #include "speedcheck.h"
 #include "getinfo.h"
 #include "transfer.h" /* for Curl_readwrite_init() */
+#include "memory.h"
 
 #define _MPRINTF_REPLACE /* use our functions only */
 #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
diff --git a/lib/ftp.c b/lib/ftp.c
index 17632044b44b3e49b7f280794cbff3400d730ece..e4a6878840c28003365a2b1ee51bdad29e5787e8 100644
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -92,6 +92,7 @@
 #include "ssluse.h"
 #include "connect.h"
 #include "strerror.h"
+#include "memory.h"
 
 #if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
 #include "inet_ntoa_r.h"
diff --git a/lib/getdate.y b/lib/getdate.y
index 0e508e4a401bb2ab430504877ece48a4652989b1..291b62990caf6f6018c91a996495de53cf052983 100644
--- a/lib/getdate.y
+++ b/lib/getdate.y
@@ -81,10 +81,9 @@
 # include <string.h>
 #endif
 
+#include "memory.h"
 /* The last #include file should be: */
-#ifdef MALLOCDEBUG
 #include "memdebug.h"
-#endif
 
 #ifndef YYMAXDEPTH
 #define YYMAXDEPTH 0
diff --git a/lib/getenv.c b/lib/getenv.c
index d29689fd1be9903037520968ebde37408afc862b..abea29a31e44f8f34c8e8371f879d327500f7d0d 100644
--- a/lib/getenv.c
+++ b/lib/getenv.c
@@ -36,10 +36,9 @@
 #endif
 
 #include <curl/curl.h>
+#include "memory.h"
 
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 static
 char *GetEnv(const char *variable)
diff --git a/lib/getinfo.c b/lib/getinfo.c
index 9e41d7f2d59f8c9987dda271f0fa8db2b520c8dd..bdb909e3c5f55ec6fd2b772166748d3edc3ef331 100644
--- a/lib/getinfo.c
+++ b/lib/getinfo.c
@@ -31,17 +31,11 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdarg.h>
-
-#ifdef	VMS
-#include	<stdlib.h>
-#endif
+#include <stdlib.h>
+#include "memory.h"
 
 /* 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
diff --git a/lib/hash.c b/lib/hash.c
index 51634e037527650b78597c38735f4447fc903a54..f33d91dc8fa9c4177bf67e9657df36bc18a213d7 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -28,12 +28,10 @@
 
 #include "hash.h"
 #include "llist.h"
+#include "memory.h"
 
-#ifdef CURLDEBUG
 /* this must be the last include file */
 #include "memdebug.h"
-#endif
-
 
 static unsigned long
 hash_str(const char *key, size_t key_length)
diff --git a/lib/hostares.c b/lib/hostares.c
index f0e98ad3542c76f2b5379d0bf48234a1ed9ba9d4..07a79fd963b66408a177f8f0f79526246dbd5b95 100644
--- a/lib/hostares.c
+++ b/lib/hostares.c
@@ -87,10 +87,10 @@
 #include "inet_ntoa_r.h"
 #endif
 
+#include "memory.h"
+
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /***********************************************************************
  * Only for ares-enabled builds
diff --git a/lib/hostasyn.c b/lib/hostasyn.c
index a38c772d20b8bebf650eab49b57e7478ccfad09e..1c22c53e25963529647f11dd9ac5c39565ca427f 100644
--- a/lib/hostasyn.c
+++ b/lib/hostasyn.c
@@ -87,10 +87,9 @@
 #include "inet_ntoa_r.h"
 #endif
 
+#include "memory.h"
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /***********************************************************************
  * Only for builds using asynchronous name resolves
diff --git a/lib/hostip.c b/lib/hostip.c
index 4adcc1455f5029ef0f0239bdd7bbaa0a602c7c05..c4e5ebfeef0e67415a9a0f6e0d01d7914c091c0a 100644
--- a/lib/hostip.c
+++ b/lib/hostip.c
@@ -87,10 +87,9 @@
 #include "inet_ntoa_r.h"
 #endif
 
+#include "memory.h"
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /*
  * hostip.c explained
diff --git a/lib/hostip4.c b/lib/hostip4.c
index 92a76baeecdf1dc055818612de2393d8337e2abb..eef1f1ab643a593f71622f02f9c49cac6911a2de 100644
--- a/lib/hostip4.c
+++ b/lib/hostip4.c
@@ -87,10 +87,9 @@
 #include "inet_ntoa_r.h"
 #endif
 
+#include "memory.h"
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /***********************************************************************
  * Only for plain-ipv4 builds
diff --git a/lib/hostip6.c b/lib/hostip6.c
index 8b3f6114660cb29e7e97a76882ebcc57a24ee3e4..9698ef3c986cc264e5b8749d94a607bc8f36ac0d 100644
--- a/lib/hostip6.c
+++ b/lib/hostip6.c
@@ -88,10 +88,9 @@
 #include "inet_ntoa_r.h"
 #endif
 
+#include "memory.h"
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /***********************************************************************
  * Only for ipv6-enabled builds
diff --git a/lib/hostsyn.c b/lib/hostsyn.c
index 7ffe222f2a8dc388ddd97cb30314600e285d115b..559043d38134e5bd0a1dd1aa8f9879f1894335fb 100644
--- a/lib/hostsyn.c
+++ b/lib/hostsyn.c
@@ -87,10 +87,9 @@
 #include "inet_ntoa_r.h"
 #endif
 
+#include "memory.h"
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /***********************************************************************
  * Only for builds using synchronous name resolves
diff --git a/lib/hostthre.c b/lib/hostthre.c
index 2a52ff329ed895e2b244e46539c2a590a6495c6e..360cad1299e97f15b974dba1a453bf84082a8a2a 100644
--- a/lib/hostthre.c
+++ b/lib/hostthre.c
@@ -85,10 +85,9 @@
 
 #include "inet_ntop.h"
 
+#include "memory.h"
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /***********************************************************************
  * Only for Windows threaded name resolves builds
diff --git a/lib/http.c b/lib/http.c
index 388f7debf81d73c9190afddcb65870e9e5c1361c..48bffa9046fe7303287cbd682b3d431520899976 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -74,7 +74,6 @@
 #include <sys/select.h>
 #endif
 
-
 #endif
 
 #include "urldata.h"
@@ -94,14 +93,13 @@
 #include "share.h"
 #include "hostip.h"
 #include "http.h"
+#include "memory.h"
 
 #define _MPRINTF_REPLACE /* use our functions only */
 #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
diff --git a/lib/http_chunks.c b/lib/http_chunks.c
index 673e8a0fe34840fb02ba0d92488dcdd59b3264ce..f939d2d06a207daefbc533fd6eb5e9058a1b8f6c 100644
--- a/lib/http_chunks.c
+++ b/lib/http_chunks.c
@@ -35,14 +35,13 @@
 
 #include "content_encoding.h"   /* 08/29/02 jhrg */
 #include "http.h"
+#include "memory.h"
 
 #define _MPRINTF_REPLACE /* use our functions only */
 #include <curl/mprintf.h>
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /* 
  * Chunk format (simplified):
diff --git a/lib/http_digest.c b/lib/http_digest.c
index bdf60d791877b9ac48abe1f31657af8e6b2ce1b8..638f69d380bf33428ea1212f5a881872c651d819 100644
--- a/lib/http_digest.c
+++ b/lib/http_digest.c
@@ -38,14 +38,13 @@
 #include "http_digest.h"
 #include "strtok.h"
 #include "url.h" /* for Curl_safefree() */
+#include "memory.h"
 
 #define _MPRINTF_REPLACE /* use our functions only */
 #include <curl/mprintf.h>
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /* Test example headers:
 
diff --git a/lib/http_negotiate.c b/lib/http_negotiate.c
index df0d6ab8418944ffeec40a759061ae9df3726b89..ece40692bc029d2e1f24a929bfdaa4896dc41081 100644
--- a/lib/http_negotiate.c
+++ b/lib/http_negotiate.c
@@ -41,14 +41,13 @@
 #include "strequal.h"
 #include "base64.h"
 #include "http_negotiate.h"
+#include "memory.h"
 
 #define _MPRINTF_REPLACE /* use our functions only */
 #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)
diff --git a/lib/http_ntlm.c b/lib/http_ntlm.c
index 9629b34d199abf39d871be2bac25c31e90205cfa..5c8d5ad2dedee894728e3f8d57cdd745e488d004 100644
--- a/lib/http_ntlm.c
+++ b/lib/http_ntlm.c
@@ -46,6 +46,7 @@
 #include "base64.h"
 #include "http_ntlm.h"
 #include "url.h"
+#include "memory.h"
 
 #define _MPRINTF_REPLACE /* use our functions only */
 #include <curl/mprintf.h>
@@ -71,9 +72,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
diff --git a/lib/if2ip.c b/lib/if2ip.c
index 94de81f8a573f283cd1d6070d4801e32b037bdae..b816d246f38b2d454cf08494be5cd51a0f288d20 100644
--- a/lib/if2ip.c
+++ b/lib/if2ip.c
@@ -73,11 +73,10 @@
 #endif
 
 #include "if2ip.h"
+#include "memory.h"
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 #define SYS_ERROR -1
 
diff --git a/lib/krb4.c b/lib/krb4.c
index 3ff22c9ad696c04fbc982a338a17020dbf281a9a..994e6111fd6a0a46919a7a41509052a79d14ac30 100644
--- a/lib/krb4.c
+++ b/lib/krb4.c
@@ -60,15 +60,14 @@
 #include "ftp.h"
 #include "sendf.h"
 #include "krb4.h"
+#include "memory.h"
 
 #if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
 #include "inet_ntoa_r.h"
 #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)
diff --git a/lib/ldap.c b/lib/ldap.c
index e773551b9a2fbbae67c03e341024111e609db7ea..968b7ac3b35a15312285f505c710a5ad2f15b562 100644
--- a/lib/ldap.c
+++ b/lib/ldap.c
@@ -56,13 +56,12 @@
 #include "strequal.h"
 #include "strtok.h"
 #include "ldap.h"
+#include "memory.h"
 
 #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).
diff --git a/lib/llist.c b/lib/llist.c
index 0f347acb92994dfb3bc8da1158a6af873204245c..2f059991db8341eb39284106cd1db5a85e8dd366 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -27,11 +27,11 @@
 #include <stdlib.h>
 
 #include "llist.h"
+#include "memory.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)
 {
diff --git a/lib/memdebug.c b/lib/memdebug.c
index 23f975ef67d603dd793ac3d4e3bb38964bcb70fd..718391cdb439f20531ca2ef5bd2c336b91fb4b38 100644
--- a/lib/memdebug.c
+++ b/lib/memdebug.c
@@ -42,6 +42,7 @@
 #endif
 
 #define MEMDEBUG_NODEFINES /* don't redefine the standard functions */
+#include "memory.h"
 #include "memdebug.h"
 
 struct memdebug {
@@ -120,7 +121,7 @@ void *curl_domalloc(size_t wantedsize, int line, const char *source)
   /* alloc at least 64 bytes */
   size = sizeof(struct memdebug)+wantedsize;
 
-  mem=(struct memdebug *)(malloc)(size);
+  mem=(struct memdebug *)(Curl_cmalloc)(size);
   if(mem) {
     /* fill memory with junk */
     memset(mem->mem, 0xA5, wantedsize);
@@ -146,7 +147,7 @@ void *curl_docalloc(size_t wanted_elements, size_t wanted_size,
   user_size = wanted_size * wanted_elements;
   size = sizeof(struct memdebug) + user_size;
 
-  mem = (struct memdebug *)(malloc)(size);
+  mem = (struct memdebug *)(Curl_cmalloc)(size);
   if(mem) {
     /* fill memory with zeroes */
     memset(mem->mem, 0, user_size);
@@ -197,7 +198,7 @@ void *curl_dorealloc(void *ptr, size_t wantedsize,
   if(ptr)
     mem = (struct memdebug *)((char *)ptr - offsetof(struct memdebug, mem));
 
-  mem=(struct memdebug *)(realloc)(mem, size);
+  mem=(struct memdebug *)(Curl_crealloc)(mem, size);
   if(logfile)
     fprintf(logfile, "MEM %s:%d realloc(0x%x, %zd) = %p\n",
             source, line, ptr, wantedsize, mem?mem->mem:NULL);
@@ -222,7 +223,7 @@ void curl_dofree(void *ptr, int line, const char *source)
   memset(mem->mem, 0x13, mem->size);
   
   /* free for real */
-  (free)(mem);
+  (Curl_cfree)(mem);
 
   if(logfile)
     fprintf(logfile, "MEM %s:%d free(%p)\n", source, line, ptr);
diff --git a/lib/mprintf.c b/lib/mprintf.c
index a9c3757783ba47801217d798a887fccca2cbee51..c9264e2cd85104b0d2cf6aad2f7ec823d2b3da8e 100644
--- a/lib/mprintf.c
+++ b/lib/mprintf.c
@@ -55,10 +55,9 @@
 #define ENABLE_64BIT
 #endif
 
+#include "memory.h"
 /* 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 */
diff --git a/lib/multi.c b/lib/multi.c
index 7d86d202ef281da520e8e59ffd79e01738c7240a..0476b1d19ca9fc74ac4dfcfc3d46af61272a9ce0 100644
--- a/lib/multi.c
+++ b/lib/multi.c
@@ -42,11 +42,10 @@
 #include "url.h"
 #include "connect.h"
 #include "progress.h"
+#include "memory.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 */
diff --git a/lib/netrc.c b/lib/netrc.c
index 1496f3ff1828ca7a3240fecc7c97d5ef5f6cdcfb..233e9018f95cee6a8f9649f946cad5ba6d9c15d9 100644
--- a/lib/netrc.c
+++ b/lib/netrc.c
@@ -45,14 +45,13 @@
 
 #include "strequal.h"
 #include "strtok.h"
+#include "memory.h"
 
 #define _MPRINTF_REPLACE /* use our functions only */
 #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'!
diff --git a/lib/nwlib.c b/lib/nwlib.c
index d54f4ac9636d8551e882de56e60bf6eb8d96aa65..2dd0f4fa556a057ab4d05235796adb9fffae5397 100644
--- a/lib/nwlib.c
+++ b/lib/nwlib.c
@@ -30,21 +30,23 @@
 #include <nks/thread.h>
 #include <nks/synch.h>
 
+#include "memory.h"
+#include "memdebug.h"
 
 typedef struct
 {
-    int     _errno;
-    void    *twentybytes;
+  int     _errno;
+  void    *twentybytes;
 } libthreaddata_t;
 
 typedef struct
 {
-    int         x;
-    int         y;
-    int         z;
-    void        *tenbytes;
-    NXKey_t     perthreadkey;   /* if -1, no key obtained... */
-    NXMutex_t   *lock;
+  int         x;
+  int         y;
+  int         z;
+  void        *tenbytes;
+  NXKey_t     perthreadkey;   /* if -1, no key obtained... */
+  NXMutex_t   *lock;
 } libdata_t;
 
 int         gLibId      = -1;
@@ -58,24 +60,24 @@ void    DisposeThreadData ( void * );
 int     GetOrSetUpData ( int id, libdata_t **data, libthreaddata_t **threaddata );
 
 
-int _NonAppStart
-(
-    void        *NLMHandle,
-    void        *errorScreen,
-    const char  *cmdLine,
-    const char  *loadDirPath,
-    size_t      uninitializedDataLength,
-    void        *NLMFileHandle,
-    int         (*readRoutineP)( int conn, void *fileHandle, size_t offset,
-                                size_t nbytes, size_t *bytesRead, void *buffer ),
-    size_t      customDataOffset,
-    size_t      customDataSize,
-    int         messageCount,
-    const char  **messages
-)
+int _NonAppStart( void        *NLMHandle,
+                  void        *errorScreen,
+                  const char  *cmdLine,
+                  const char  *loadDirPath,
+                  size_t      uninitializedDataLength,
+                  void        *NLMFileHandle,
+                  int         (*readRoutineP)( int conn,
+                                               void *fileHandle, size_t offset,
+                                               size_t nbytes,
+                                               size_t *bytesRead,
+                                               void *buffer ),
+                  size_t      customDataOffset,
+                  size_t      customDataSize,
+                  int         messageCount,
+                  const char  **messages )
 {
-    NX_LOCK_INFO_ALLOC(liblock, "Per-Application Data Lock", 0);
-
+  NX_LOCK_INFO_ALLOC(liblock, "Per-Application Data Lock", 0);
+  
 #ifndef __GNUC__
 #pragma unused(cmdLine)
 #pragma unused(loadDirPath)
@@ -94,35 +96,33 @@ int _NonAppStart
 ** to accept calls into us. If we succeed, we return non-zero and the NetWare
 ** Loader will leave us up, otherwise we fail to load and get dumped.
 */
-    gAllocTag = AllocateResourceTag(NLMHandle,
-                                "<library-name> memory allocations", AllocSignature);
+  gAllocTag = AllocateResourceTag(NLMHandle,
+                                  "<library-name> memory allocations",
+                                  AllocSignature);
 
-    if (!gAllocTag)
-    {
-        OutputToScreen(errorScreen, "Unable to allocate resource tag for "
-                                            "library memory allocations.\n");
-        return -1;
-    }
+  if (!gAllocTag) {
+    OutputToScreen(errorScreen, "Unable to allocate resource tag for "
+                   "library memory allocations.\n");
+    return -1;
+  }
 
-    gLibId = register_library(DisposeLibraryData);
+  gLibId = register_library(DisposeLibraryData);
 
-    if (gLibId < -1)
-    {
-        OutputToScreen(errorScreen, "Unable to register library with kernel.\n");
-        return -1;
-    }
+  if (gLibId < -1) {
+    OutputToScreen(errorScreen, "Unable to register library with kernel.\n");
+    return -1;
+  }
 
-    gLibHandle = NLMHandle;
+  gLibHandle = NLMHandle;
 
-    gLibLock = NXMutexAlloc(0, 0, &liblock);
-
-    if (!gLibLock)
-    {
-        OutputToScreen(errorScreen, "Unable to allocate library data lock.\n");
-        return -1;
-    }
+  gLibLock = NXMutexAlloc(0, 0, &liblock);
+  
+  if (!gLibLock) {
+    OutputToScreen(errorScreen, "Unable to allocate library data lock.\n");
+    return -1;
+  }
 
-    return 0;
+  return 0;
 }
 
 /*
@@ -131,8 +131,8 @@ int _NonAppStart
 */
 void _NonAppStop( void )
 {
-    (void) unregister_library(gLibId);
-    NXMutexFree(gLibLock);
+  (void) unregister_library(gLibId);
+  NXMutexFree(gLibLock);
 }
 
 /*
@@ -151,31 +151,26 @@ int  _NonAppCheckUnload( void )
     return 0;
 }
 
-int GetOrSetUpData
-(
-    int                 id,
-    libdata_t           **appData,
-    libthreaddata_t **threadData
-)
+int GetOrSetUpData(int id, libdata_t **appData,
+                   libthreaddata_t **threadData )
 {
-    int                 err;
-    libdata_t           *app_data;
-    libthreaddata_t *thread_data;
-    NXKey_t             key;
-    NX_LOCK_INFO_ALLOC(liblock, "Application Data Lock", 0);
+  int                 err;
+  libdata_t           *app_data;
+  libthreaddata_t *thread_data;
+  NXKey_t             key;
+  NX_LOCK_INFO_ALLOC(liblock, "Application Data Lock", 0);
 
-    err         = 0;
-    thread_data = (libthreaddata_t *) NULL;
+  err         = 0;
+  thread_data = (libthreaddata_t *) NULL;
 
 /*
 ** Attempt to get our data for the application calling us. This is where we
 ** store whatever application-specific information we need to carry in support
 ** of calling applications.
 */
-    app_data = (libdata_t *) get_app_data(id);
+  app_data = (libdata_t *) get_app_data(id);
 
-    if (!app_data)
-    {
+  if (!app_data) {
 /*
 ** This application hasn't called us before; set up application AND per-thread
 ** data. Of course, just in case a thread from this same application is calling
@@ -184,31 +179,27 @@ int GetOrSetUpData
 ** that other thread that was too late to create the data and the first thread
 ** in will have created it.
 */
-        NXLock(gLibLock);
-
-        if (!(app_data = (libdata_t *) get_app_data(id)))
-        {
-            app_data = (libdata_t *) malloc(sizeof(libdata_t));
-
-            if (app_data)
-            {
-                memset(app_data, 0, sizeof(libdata_t));
-
-                app_data->tenbytes = malloc(10);
-                app_data->lock     = NXMutexAlloc(0, 0, &liblock);
-
-                if (!app_data->tenbytes || !app_data->lock)
-                {
-                    if (app_data->lock)
-                        NXMutexFree(app_data->lock);
-
-                    free(app_data);
-                    app_data = (libdata_t *) NULL;
-                    err      = ENOMEM;
-                }
-
-                if (app_data)
-                {
+    NXLock(gLibLock);
+
+    if (!(app_data = (libdata_t *) get_app_data(id))) {
+      app_data = (libdata_t *) malloc(sizeof(libdata_t));
+
+      if (app_data) {
+        memset(app_data, 0, sizeof(libdata_t));
+        
+        app_data->tenbytes = malloc(10);
+        app_data->lock     = NXMutexAlloc(0, 0, &liblock);
+        
+        if (!app_data->tenbytes || !app_data->lock) {
+          if (app_data->lock)
+            NXMutexFree(app_data->lock);
+          
+          free(app_data);
+          app_data = (libdata_t *) NULL;
+          err      = ENOMEM;
+        }
+        
+        if (app_data) {
 /*
 ** Here we burn in the application data that we were trying to get by calling
 ** get_app_data(). Next time we call the first function, we'll get this data
@@ -216,39 +207,35 @@ int GetOrSetUpData
 ** for the calling thread, something we'll have to do on each application
 ** thread the first time it calls us.
 */
-                    err = set_app_data(gLibId, app_data);
-
-                    if (err)
-                    {
-                        free(app_data);
-                        app_data = (libdata_t *) NULL;
-                        err      = ENOMEM;
-                    }
-                    else
-                    {
-                        /* create key for thread-specific data... */
-                        err = NXKeyCreate(DisposeThreadData, (void *) NULL, &key);
-
-                        if (err)                /* (no more keys left?) */
-                            key = -1;
-
-                        app_data->perthreadkey = key;
-                    }
-                }
-            }
+          err = set_app_data(gLibId, app_data);
+          
+          if (err) {
+            free(app_data);
+            app_data = (libdata_t *) NULL;
+            err      = ENOMEM;
+          }
+          else {
+            /* create key for thread-specific data... */
+            err = NXKeyCreate(DisposeThreadData, (void *) NULL, &key);
+            
+            if (err)                /* (no more keys left?) */
+              key = -1;
+            
+            app_data->perthreadkey = key;
+          }
         }
-
-        NXUnlock(gLibLock);
+      }
     }
-
-    if (app_data)
-    {
-        key = app_data->perthreadkey;
-
-        if (     key != -1                  /* couldn't create a key? no thread data */
-            && !(err = NXKeyGetValue(key, (void **) &thread_data))
-            && !thread_data)
-        {
+    
+    NXUnlock(gLibLock);
+  }
+
+  if (app_data) {
+    key = app_data->perthreadkey;
+    
+    if (key != -1 /* couldn't create a key? no thread data */
+        && !(err = NXKeyGetValue(key, (void **) &thread_data))
+        && !thread_data) {
 /*
 ** Allocate the per-thread data for the calling thread. Regardless of whether
 ** there was already application data or not, this may be the first call by a
@@ -256,71 +243,58 @@ int GetOrSetUpData
 ** important, this just helps to demonstrate that we can have arbitrarily
 ** complex per-thread data.
 */
-            thread_data = (libthreaddata_t *) malloc(sizeof(libthreaddata_t));
-
-            if (thread_data)
-            {
-                thread_data->_errno      = 0;
-                thread_data->twentybytes = malloc(20);
-
-                if (!thread_data->twentybytes)
-                {
-                    free(thread_data);
-                    thread_data = (libthreaddata_t *) NULL;
-                    err         = ENOMEM;
-                }
-
-                if ((err = NXKeySetValue(key, thread_data)))
-                {
-                    free(thread_data->twentybytes);
-                    free(thread_data);
-                    thread_data = (libthreaddata_t *) NULL;
-                }
-            }
+      thread_data = (libthreaddata_t *) malloc(sizeof(libthreaddata_t));
+      
+      if (thread_data) {
+        thread_data->_errno      = 0;
+        thread_data->twentybytes = malloc(20);
+          
+        if (!thread_data->twentybytes) {
+          free(thread_data);
+          thread_data = (libthreaddata_t *) NULL;
+          err         = ENOMEM;
+        }
+        
+        if ((err = NXKeySetValue(key, thread_data))) {
+          free(thread_data->twentybytes);
+          free(thread_data);
+          thread_data = (libthreaddata_t *) NULL;
         }
+      }
     }
+  }
 
-    if (appData)
-        *appData = app_data;
+  if (appData)
+    *appData = app_data;
 
-    if (threadData)
-        *threadData = thread_data;
+  if (threadData)
+    *threadData = thread_data;
 
-    return err;
+  return err;
 }
 
-int DisposeLibraryData
-(
-    void    *data
-)
+int DisposeLibraryData( void    *data)
 {
-    if (data)
-    {
-        void    *tenbytes = ((libdata_t *) data)->tenbytes;
-
-        if (tenbytes)
-            free(tenbytes);
-
-        free(data);
-    }
-
-    return 0;
+  if (data) {
+    void    *tenbytes = ((libdata_t *) data)->tenbytes;
+    
+    if (tenbytes)
+      free(tenbytes);
+    
+    free(data);
+  }
+
+  return 0;
 }
 
-void DisposeThreadData
-(
-    void    *data
-)
+void DisposeThreadData(void    *data)
 {
-    if (data)
-    {
-        void    *twentybytes = ((libthreaddata_t *) data)->twentybytes;
-
-        if (twentybytes)
-            free(twentybytes);
-
-        free(data);
-    }
+  if (data) {
+    void    *twentybytes = ((libthreaddata_t *) data)->twentybytes;
+    
+    if (twentybytes)
+      free(twentybytes);
+    
+    free(data);
+  }
 }
-
-
diff --git a/lib/security.c b/lib/security.c
index 16746cdc950034658224953273fe55ce0792a83a..f1af44201b1b607887ea26c115811c6a8ed3feec 100644
--- a/lib/security.c
+++ b/lib/security.c
@@ -58,11 +58,10 @@
 #include "base64.h"
 #include "sendf.h"
 #include "ftp.h"
+#include "memory.h"
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 #define min(a, b)   ((a) < (b) ? (a) : (b))
 
diff --git a/lib/sendf.c b/lib/sendf.c
index 4c3405566b5902502c8d69343596b4042fff7f01..1f6665eddb6d3d767c4a1a0ecf65ee103664873f 100644
--- a/lib/sendf.c
+++ b/lib/sendf.c
@@ -52,10 +52,9 @@
 #include "security.h"
 #endif
 #include <string.h>
+#include "memory.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)
diff --git a/lib/share.c b/lib/share.c
index e554339dec7afa8ceff082697b7d1ec8b073403a..ced7e188da2bc071895887ba874483d02b990cd7 100644
--- a/lib/share.c
+++ b/lib/share.c
@@ -28,11 +28,10 @@
 #include <curl/curl.h>
 #include "urldata.h"
 #include "share.h"
+#include "memory.h"
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 CURLSH *
 curl_share_init(void)
diff --git a/lib/ssluse.c b/lib/ssluse.c
index c27eb918c0d344ff22d0776753dce14bf1c950ee..c2a16d1364baba10fe4f0ea8e5b86acd80aab9b2 100644
--- a/lib/ssluse.c
+++ b/lib/ssluse.c
@@ -50,10 +50,10 @@
 #include <openssl/rand.h>
 #include <openssl/x509v3.h>
 
+#include "memory.h"
+
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 #if OPENSSL_VERSION_NUMBER >= 0x0090581fL
 #define HAVE_SSL_GET1_SESSION 1
diff --git a/lib/telnet.c b/lib/telnet.c
index c133b5fd61668dc66feb61e4bdfa0fb6feca24bd..0408d73208ebb1ac337234fdb8f2024dba521d26 100644
--- a/lib/telnet.c
+++ b/lib/telnet.c
@@ -81,11 +81,10 @@
 #define  TELCMDS
 
 #include "arpa_telnet.h"
+#include "memory.h"
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 #define SUBBUFSIZE 512
 
diff --git a/lib/transfer.c b/lib/transfer.c
index 5d8fd73066a27332362e044e51a97e5a600ccc78..1371e8de5aac7c3449b52f37475f1a6d99471e73 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -101,14 +101,13 @@
 #include "http_ntlm.h"
 #include "http_negotiate.h"
 #include "share.h"
+#include "memory.h"
 
 #define _MPRINTF_REPLACE /* use our functions only */
 #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 */
 
diff --git a/lib/url.c b/lib/url.c
index fc7a9d4e0be293961ad637e086cfe9d2ab6e1082..66012ef32a5076d7be7b47f2a049b5d08f12f3c1 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -134,11 +134,10 @@
 #ifdef HAVE_KRB4
 #include "security.h"
 #endif
+#include "memory.h"
 
 /* The last #include file should be: */
-#ifdef CURLDEBUG
 #include "memdebug.h"
-#endif
 
 /* Local static prototypes */
 static int ConnectionKillOne(struct SessionHandle *data);
diff --git a/tests/runtests.pl b/tests/runtests.pl
index dbe5978f8f31235f6cb45cca4eaafd78d955801b..0df1e0550d49479b593e2f6bb1cc5b08b867b163 100755
--- a/tests/runtests.pl
+++ b/tests/runtests.pl
@@ -635,7 +635,7 @@ sub checkcurl {
 
     my $curl;
     my $libcurl;
-    my @version=`$CURL -V 2>/dev/null`;
+    my @version=`strace $CURL --version 2>fump`;
     for(@version) {
         chomp;
 
@@ -727,7 +727,7 @@ sub checkcurl {
         }
     }
     if(!$curl) {
-        die "couldn't run curl!"
+        die "couldn't run '$CURL'"
     }
 
     my $hostname=`hostname`;