curl_global_init_mem() allows the memory functions to be replaced.

memory.h is included everywhere for this.
This commit is contained in:
Daniel Stenberg 2004-05-11 11:30:23 +00:00
parent 434bc13812
commit bbafb2eb27
48 changed files with 295 additions and 271 deletions

View File

@ -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)

View File

@ -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

View File

@ -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?

View File

@ -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)

View File

@ -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), "

View File

@ -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()
*

View File

@ -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 \

View File

@ -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)
{

View File

@ -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);

View File

@ -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 */

View File

@ -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

View File

@ -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.

View File

@ -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)
{

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -36,10 +36,9 @@
#endif
#include <curl/curl.h>
#include "memory.h"
#ifdef CURLDEBUG
#include "memdebug.h"
#endif
static
char *GetEnv(const char *variable)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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:

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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).

View File

@ -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)
{

View File

@ -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);

View File

@ -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 */

View File

@ -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 */

View File

@ -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'!

View File

@ -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);
gLibLock = NXMutexAlloc(0, 0, &liblock);
if (!gLibLock) {
OutputToScreen(errorScreen, "Unable to allocate library data lock.\n");
return -1;
}
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);
NXLock(gLibLock);
if (!(app_data = (libdata_t *) get_app_data(id)))
{
app_data = (libdata_t *) malloc(sizeof(libdata_t));
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)
{
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);
}
}
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)
{
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 (data) {
void *tenbytes = ((libdata_t *) data)->tenbytes;
if (tenbytes)
free(tenbytes);
free(data);
}
if (tenbytes)
free(tenbytes);
free(data);
}
return 0;
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);
}
}

View File

@ -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))

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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 */

View File

@ -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);

View File

@ -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`;