aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am4
-rw-r--r--lib/base64.c5
-rw-r--r--lib/connect.c3
-rw-r--r--lib/content_encoding.c3
-rw-r--r--lib/cookie.c1
-rw-r--r--lib/easy.c51
-rw-r--r--lib/escape.c3
-rw-r--r--lib/file.c4
-rw-r--r--lib/ftp.c1
-rw-r--r--lib/getdate.y3
-rw-r--r--lib/getenv.c3
-rw-r--r--lib/getinfo.c10
-rw-r--r--lib/hash.c4
-rw-r--r--lib/hostares.c4
-rw-r--r--lib/hostasyn.c3
-rw-r--r--lib/hostip.c3
-rw-r--r--lib/hostip4.c3
-rw-r--r--lib/hostip6.c3
-rw-r--r--lib/hostsyn.c3
-rw-r--r--lib/hostthre.c3
-rw-r--r--lib/http.c4
-rw-r--r--lib/http_chunks.c3
-rw-r--r--lib/http_digest.c3
-rw-r--r--lib/http_negotiate.c3
-rw-r--r--lib/http_ntlm.c3
-rw-r--r--lib/if2ip.c3
-rw-r--r--lib/krb4.c3
-rw-r--r--lib/ldap.c3
-rw-r--r--lib/llist.c4
-rw-r--r--lib/memdebug.c9
-rw-r--r--lib/mprintf.c3
-rw-r--r--lib/multi.c3
-rw-r--r--lib/netrc.c3
-rw-r--r--lib/nwlib.c330
-rw-r--r--lib/security.c3
-rw-r--r--lib/sendf.c3
-rw-r--r--lib/share.c3
-rw-r--r--lib/ssluse.c4
-rw-r--r--lib/telnet.c3
-rw-r--r--lib/transfer.c3
-rw-r--r--lib/url.c3
41 files changed, 253 insertions, 263 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index d9038f7d5..d1dc1910f 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 4af1d72e7..70e5e5cc2 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 c7dee3ce2..0eec75a48 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 a36bba778..2a0aaf402 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 41f14011f..4e5818c72 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 c04f01e2a..c162ef531 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 23c3821fa..b233600af 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 004718cd4..0edd3d972 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 17632044b..e4a687884 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 0e508e4a4..291b62990 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 d29689fd1..abea29a31 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 9e41d7f2d..bdb909e3c 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 51634e037..f33d91dc8 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 f0e98ad35..07a79fd96 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 a38c772d2..1c22c53e2 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 4adcc1455..c4e5ebfee 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 92a76baee..eef1f1ab6 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 8b3f61146..9698ef3c9 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 7ffe222f2..559043d38 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 2a52ff329..360cad129 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 388f7debf..48bffa904 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 673e8a0fe..f939d2d06 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 bdf60d791..638f69d38 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 df0d6ab84..ece40692b 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 9629b34d1..5c8d5ad2d 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 94de81f8a..b816d246f 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 3ff22c9ad..994e6111f 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 e773551b9..968b7ac3b 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 0f347acb9..2f059991d 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 23f975ef6..718391cdb 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 a9c375778..c9264e2cd 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 7d86d202e..0476b1d19 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 1496f3ff1..233e9018f 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 d54f4ac96..2dd0f4fa5 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 16746cdc9..f1af44201 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 4c3405566..1f6665edd 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 e554339de..ced7e188d 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 c27eb918c..c2a16d136 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 c133b5fd6..0408d7320 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 5d8fd7306..1371e8de5 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 fc7a9d4e0..66012ef32 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);