memdebug: make debug-specific functions use curl_dbg_ prefix

To not "collide" or use up the regular curl_ name space. Also makes them
easier to detect in helper scripts.

Closes #3656
This commit is contained in:
Daniel Stenberg 2019-03-08 10:47:29 +01:00
parent 50afa478e1
commit 76b6348949
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
7 changed files with 149 additions and 167 deletions

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -539,7 +539,7 @@ Curl_addrinfo *Curl_unix2addr(const char *path, bool *longpath, bool abstract)
#if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) && \ #if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) && \
defined(HAVE_FREEADDRINFO) defined(HAVE_FREEADDRINFO)
/* /*
* curl_dofreeaddrinfo() * curl_dbg_freeaddrinfo()
* *
* This is strictly for memory tracing and are using the same style as the * This is strictly for memory tracing and are using the same style as the
* family otherwise present in memdebug.c. I put these ones here since they * family otherwise present in memdebug.c. I put these ones here since they
@ -547,23 +547,23 @@ Curl_addrinfo *Curl_unix2addr(const char *path, bool *longpath, bool abstract)
*/ */
void void
curl_dofreeaddrinfo(struct addrinfo *freethis, curl_dbg_freeaddrinfo(struct addrinfo *freethis,
int line, const char *source) int line, const char *source)
{ {
#ifdef USE_LWIPSOCK #ifdef USE_LWIPSOCK
lwip_freeaddrinfo(freethis); lwip_freeaddrinfo(freethis);
#else #else
(freeaddrinfo)(freethis); (freeaddrinfo)(freethis);
#endif #endif
curl_memlog("ADDR %s:%d freeaddrinfo(%p)\n", curl_dbg_log("ADDR %s:%d freeaddrinfo(%p)\n",
source, line, (void *)freethis); source, line, (void *)freethis);
} }
#endif /* defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO) */ #endif /* defined(CURLDEBUG) && defined(HAVE_FREEADDRINFO) */
#if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) #if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO)
/* /*
* curl_dogetaddrinfo() * curl_dbg_getaddrinfo()
* *
* This is strictly for memory tracing and are using the same style as the * This is strictly for memory tracing and are using the same style as the
* family otherwise present in memdebug.c. I put these ones here since they * family otherwise present in memdebug.c. I put these ones here since they
@ -571,11 +571,11 @@ curl_dofreeaddrinfo(struct addrinfo *freethis,
*/ */
int int
curl_dogetaddrinfo(const char *hostname, curl_dbg_getaddrinfo(const char *hostname,
const char *service, const char *service,
const struct addrinfo *hints, const struct addrinfo *hints,
struct addrinfo **result, struct addrinfo **result,
int line, const char *source) int line, const char *source)
{ {
#ifdef USE_LWIPSOCK #ifdef USE_LWIPSOCK
int res = lwip_getaddrinfo(hostname, service, hints, result); int res = lwip_getaddrinfo(hostname, service, hints, result);
@ -584,11 +584,11 @@ curl_dogetaddrinfo(const char *hostname,
#endif #endif
if(0 == res) if(0 == res)
/* success */ /* success */
curl_memlog("ADDR %s:%d getaddrinfo() = %p\n", curl_dbg_log("ADDR %s:%d getaddrinfo() = %p\n",
source, line, (void *)*result); source, line, (void *)*result);
else else
curl_memlog("ADDR %s:%d getaddrinfo() failed\n", curl_dbg_log("ADDR %s:%d getaddrinfo() failed\n",
source, line); source, line);
return res; return res;
} }
#endif /* defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) */ #endif /* defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) */

View File

@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -86,17 +86,14 @@ Curl_addrinfo *Curl_unix2addr(const char *path, bool *longpath, bool abstract);
#if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) && \ #if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) && \
defined(HAVE_FREEADDRINFO) defined(HAVE_FREEADDRINFO)
void void
curl_dofreeaddrinfo(struct addrinfo *freethis, curl_dbg_freeaddrinfo(struct addrinfo *freethis, int line, const char *source);
int line, const char *source);
#endif #endif
#if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO) #if defined(CURLDEBUG) && defined(HAVE_GETADDRINFO)
int int
curl_dogetaddrinfo(const char *hostname, curl_dbg_getaddrinfo(const char *hostname, const char *service,
const char *service, const struct addrinfo *hints, struct addrinfo **result,
const struct addrinfo *hints, int line, const char *source);
struct addrinfo **result,
int line, const char *source);
#endif #endif
#ifdef HAVE_GETADDRINFO #ifdef HAVE_GETADDRINFO

View File

@ -100,19 +100,18 @@ struct memdebug {
* Don't use these with multithreaded test programs! * Don't use these with multithreaded test programs!
*/ */
#define logfile curl_debuglogfile FILE *curl_dbg_logfile = NULL;
FILE *curl_debuglogfile = NULL;
static bool memlimit = FALSE; /* enable memory limit */ static bool memlimit = FALSE; /* enable memory limit */
static long memsize = 0; /* set number of mallocs allowed */ static long memsize = 0; /* set number of mallocs allowed */
/* this sets the log file name */ /* this sets the log file name */
void curl_memdebug(const char *logname) void curl_dbg_memdebug(const char *logname)
{ {
if(!logfile) { if(!curl_dbg_logfile) {
if(logname && *logname) if(logname && *logname)
logfile = fopen(logname, FOPEN_WRITETEXT); curl_dbg_logfile = fopen(logname, FOPEN_WRITETEXT);
else else
logfile = stderr; curl_dbg_logfile = stderr;
#ifdef MEMDEBUG_LOG_SYNC #ifdef MEMDEBUG_LOG_SYNC
/* Flush the log file after every line so the log isn't lost in a crash */ /* Flush the log file after every line so the log isn't lost in a crash */
if(logfile) if(logfile)
@ -123,7 +122,7 @@ void curl_memdebug(const char *logname)
/* This function sets the number of malloc() calls that should return /* This function sets the number of malloc() calls that should return
successfully! */ successfully! */
void curl_memlimit(long limit) void curl_dbg_memlimit(long limit)
{ {
if(!memlimit) { if(!memlimit) {
memlimit = TRUE; memlimit = TRUE;
@ -140,12 +139,12 @@ static bool countcheck(const char *func, int line, const char *source)
if(!memsize) { if(!memsize) {
if(source) { if(source) {
/* log to file */ /* log to file */
curl_memlog("LIMIT %s:%d %s reached memlimit\n", curl_dbg_log("LIMIT %s:%d %s reached memlimit\n",
source, line, func); source, line, func);
/* log to stderr also */ /* log to stderr also */
fprintf(stderr, "LIMIT %s:%d %s reached memlimit\n", fprintf(stderr, "LIMIT %s:%d %s reached memlimit\n",
source, line, func); source, line, func);
fflush(logfile); /* because it might crash now */ fflush(curl_dbg_logfile); /* because it might crash now */
} }
errno = ENOMEM; errno = ENOMEM;
return TRUE; /* RETURN ERROR! */ return TRUE; /* RETURN ERROR! */
@ -159,7 +158,7 @@ static bool countcheck(const char *func, int line, const char *source)
return FALSE; /* allow this */ return FALSE; /* allow this */
} }
void *curl_domalloc(size_t wantedsize, int line, const char *source) void *curl_dbg_malloc(size_t wantedsize, int line, const char *source)
{ {
struct memdebug *mem; struct memdebug *mem;
size_t size; size_t size;
@ -180,15 +179,15 @@ void *curl_domalloc(size_t wantedsize, int line, const char *source)
} }
if(source) if(source)
curl_memlog("MEM %s:%d malloc(%zu) = %p\n", curl_dbg_log("MEM %s:%d malloc(%zu) = %p\n",
source, line, wantedsize, source, line, wantedsize,
mem ? (void *)mem->mem : (void *)0); mem ? (void *)mem->mem : (void *)0);
return (mem ? mem->mem : NULL); return (mem ? mem->mem : NULL);
} }
void *curl_docalloc(size_t wanted_elements, size_t wanted_size, void *curl_dbg_calloc(size_t wanted_elements, size_t wanted_size,
int line, const char *source) int line, const char *source)
{ {
struct memdebug *mem; struct memdebug *mem;
size_t size, user_size; size_t size, user_size;
@ -208,14 +207,14 @@ void *curl_docalloc(size_t wanted_elements, size_t wanted_size,
mem->size = user_size; mem->size = user_size;
if(source) if(source)
curl_memlog("MEM %s:%d calloc(%zu,%zu) = %p\n", curl_dbg_log("MEM %s:%d calloc(%zu,%zu) = %p\n",
source, line, wanted_elements, wanted_size, source, line, wanted_elements, wanted_size,
mem ? (void *)mem->mem : (void *)0); mem ? (void *)mem->mem : (void *)0);
return (mem ? mem->mem : NULL); return (mem ? mem->mem : NULL);
} }
char *curl_dostrdup(const char *str, int line, const char *source) char *curl_dbg_strdup(const char *str, int line, const char *source)
{ {
char *mem; char *mem;
size_t len; size_t len;
@ -227,19 +226,19 @@ char *curl_dostrdup(const char *str, int line, const char *source)
len = strlen(str) + 1; len = strlen(str) + 1;
mem = curl_domalloc(len, 0, NULL); /* NULL prevents logging */ mem = curl_dbg_malloc(len, 0, NULL); /* NULL prevents logging */
if(mem) if(mem)
memcpy(mem, str, len); memcpy(mem, str, len);
if(source) if(source)
curl_memlog("MEM %s:%d strdup(%p) (%zu) = %p\n", curl_dbg_log("MEM %s:%d strdup(%p) (%zu) = %p\n",
source, line, (const void *)str, len, (const void *)mem); source, line, (const void *)str, len, (const void *)mem);
return mem; return mem;
} }
#if defined(WIN32) && defined(UNICODE) #if defined(WIN32) && defined(UNICODE)
wchar_t *curl_dowcsdup(const wchar_t *str, int line, const char *source) wchar_t *curl_dbg_wcsdup(const wchar_t *str, int line, const char *source)
{ {
wchar_t *mem; wchar_t *mem;
size_t wsiz, bsiz; size_t wsiz, bsiz;
@ -252,12 +251,12 @@ wchar_t *curl_dowcsdup(const wchar_t *str, int line, const char *source)
wsiz = wcslen(str) + 1; wsiz = wcslen(str) + 1;
bsiz = wsiz * sizeof(wchar_t); bsiz = wsiz * sizeof(wchar_t);
mem = curl_domalloc(bsiz, 0, NULL); /* NULL prevents logging */ mem = curl_dbg_malloc(bsiz, 0, NULL); /* NULL prevents logging */
if(mem) if(mem)
memcpy(mem, str, bsiz); memcpy(mem, str, bsiz);
if(source) if(source)
curl_memlog("MEM %s:%d wcsdup(%p) (%zu) = %p\n", curl_dbg_log("MEM %s:%d wcsdup(%p) (%zu) = %p\n",
source, line, (void *)str, bsiz, (void *)mem); source, line, (void *)str, bsiz, (void *)mem);
return mem; return mem;
@ -266,8 +265,8 @@ wchar_t *curl_dowcsdup(const wchar_t *str, int line, const char *source)
/* We provide a realloc() that accepts a NULL as pointer, which then /* We provide a realloc() that accepts a NULL as pointer, which then
performs a malloc(). In order to work with ares. */ performs a malloc(). In order to work with ares. */
void *curl_dorealloc(void *ptr, size_t wantedsize, void *curl_dbg_realloc(void *ptr, size_t wantedsize,
int line, const char *source) int line, const char *source)
{ {
struct memdebug *mem = NULL; struct memdebug *mem = NULL;
@ -293,7 +292,7 @@ void *curl_dorealloc(void *ptr, size_t wantedsize,
mem = (Curl_crealloc)(mem, size); mem = (Curl_crealloc)(mem, size);
if(source) if(source)
curl_memlog("MEM %s:%d realloc(%p, %zu) = %p\n", curl_dbg_log("MEM %s:%d realloc(%p, %zu) = %p\n",
source, line, (void *)ptr, wantedsize, source, line, (void *)ptr, wantedsize,
mem ? (void *)mem->mem : (void *)0); mem ? (void *)mem->mem : (void *)0);
@ -305,7 +304,7 @@ void *curl_dorealloc(void *ptr, size_t wantedsize,
return NULL; return NULL;
} }
void curl_dofree(void *ptr, int line, const char *source) void curl_dbg_free(void *ptr, int line, const char *source)
{ {
struct memdebug *mem; struct memdebug *mem;
@ -331,11 +330,11 @@ void curl_dofree(void *ptr, int line, const char *source)
} }
if(source) if(source)
curl_memlog("MEM %s:%d free(%p)\n", source, line, (void *)ptr); curl_dbg_log("MEM %s:%d free(%p)\n", source, line, (void *)ptr);
} }
curl_socket_t curl_socket(int domain, int type, int protocol, curl_socket_t curl_dbg_socket(int domain, int type, int protocol,
int line, const char *source) int line, const char *source)
{ {
const char *fmt = (sizeof(curl_socket_t) == sizeof(int)) ? const char *fmt = (sizeof(curl_socket_t) == sizeof(int)) ?
"FD %s:%d socket() = %d\n" : "FD %s:%d socket() = %d\n" :
@ -351,44 +350,44 @@ curl_socket_t curl_socket(int domain, int type, int protocol,
sockfd = socket(domain, type, protocol); sockfd = socket(domain, type, protocol);
if(source && (sockfd != CURL_SOCKET_BAD)) if(source && (sockfd != CURL_SOCKET_BAD))
curl_memlog(fmt, source, line, sockfd); curl_dbg_log(fmt, source, line, sockfd);
return sockfd; return sockfd;
} }
SEND_TYPE_RETV curl_dosend(SEND_TYPE_ARG1 sockfd, SEND_TYPE_RETV curl_dbg_send(SEND_TYPE_ARG1 sockfd,
SEND_QUAL_ARG2 SEND_TYPE_ARG2 buf, SEND_QUAL_ARG2 SEND_TYPE_ARG2 buf,
SEND_TYPE_ARG3 len, SEND_TYPE_ARG4 flags, int line, SEND_TYPE_ARG3 len, SEND_TYPE_ARG4 flags, int line,
const char *source) const char *source)
{ {
SEND_TYPE_RETV rc; SEND_TYPE_RETV rc;
if(countcheck("send", line, source)) if(countcheck("send", line, source))
return -1; return -1;
rc = send(sockfd, buf, len, flags); rc = send(sockfd, buf, len, flags);
if(source) if(source)
curl_memlog("SEND %s:%d send(%lu) = %ld\n", curl_dbg_log("SEND %s:%d send(%lu) = %ld\n",
source, line, (unsigned long)len, (long)rc); source, line, (unsigned long)len, (long)rc);
return rc; return rc;
} }
RECV_TYPE_RETV curl_dorecv(RECV_TYPE_ARG1 sockfd, RECV_TYPE_ARG2 buf, RECV_TYPE_RETV curl_dbg_recv(RECV_TYPE_ARG1 sockfd, RECV_TYPE_ARG2 buf,
RECV_TYPE_ARG3 len, RECV_TYPE_ARG4 flags, int line, RECV_TYPE_ARG3 len, RECV_TYPE_ARG4 flags, int line,
const char *source) const char *source)
{ {
RECV_TYPE_RETV rc; RECV_TYPE_RETV rc;
if(countcheck("recv", line, source)) if(countcheck("recv", line, source))
return -1; return -1;
rc = recv(sockfd, buf, len, flags); rc = recv(sockfd, buf, len, flags);
if(source) if(source)
curl_memlog("RECV %s:%d recv(%lu) = %ld\n", curl_dbg_log("RECV %s:%d recv(%lu) = %ld\n",
source, line, (unsigned long)len, (long)rc); source, line, (unsigned long)len, (long)rc);
return rc; return rc;
} }
#ifdef HAVE_SOCKETPAIR #ifdef HAVE_SOCKETPAIR
int curl_socketpair(int domain, int type, int protocol, int curl_dbg_socketpair(int domain, int type, int protocol,
curl_socket_t socket_vector[2], curl_socket_t socket_vector[2],
int line, const char *source) int line, const char *source)
{ {
const char *fmt = (sizeof(curl_socket_t) == sizeof(int)) ? const char *fmt = (sizeof(curl_socket_t) == sizeof(int)) ?
"FD %s:%d socketpair() = %d %d\n" : "FD %s:%d socketpair() = %d %d\n" :
@ -399,14 +398,14 @@ int curl_socketpair(int domain, int type, int protocol,
int res = socketpair(domain, type, protocol, socket_vector); int res = socketpair(domain, type, protocol, socket_vector);
if(source && (0 == res)) if(source && (0 == res))
curl_memlog(fmt, source, line, socket_vector[0], socket_vector[1]); curl_dbg_log(fmt, source, line, socket_vector[0], socket_vector[1]);
return res; return res;
} }
#endif #endif
curl_socket_t curl_accept(curl_socket_t s, void *saddr, void *saddrlen, curl_socket_t curl_dbg_accept(curl_socket_t s, void *saddr, void *saddrlen,
int line, const char *source) int line, const char *source)
{ {
const char *fmt = (sizeof(curl_socket_t) == sizeof(int)) ? const char *fmt = (sizeof(curl_socket_t) == sizeof(int)) ?
"FD %s:%d accept() = %d\n" : "FD %s:%d accept() = %d\n" :
@ -420,13 +419,13 @@ curl_socket_t curl_accept(curl_socket_t s, void *saddr, void *saddrlen,
curl_socket_t sockfd = accept(s, addr, addrlen); curl_socket_t sockfd = accept(s, addr, addrlen);
if(source && (sockfd != CURL_SOCKET_BAD)) if(source && (sockfd != CURL_SOCKET_BAD))
curl_memlog(fmt, source, line, sockfd); curl_dbg_log(fmt, source, line, sockfd);
return sockfd; return sockfd;
} }
/* separate function to allow libcurl to mark a "faked" close */ /* separate function to allow libcurl to mark a "faked" close */
void curl_mark_sclose(curl_socket_t sockfd, int line, const char *source) void curl_dbg_mark_sclose(curl_socket_t sockfd, int line, const char *source)
{ {
const char *fmt = (sizeof(curl_socket_t) == sizeof(int)) ? const char *fmt = (sizeof(curl_socket_t) == sizeof(int)) ?
"FD %s:%d sclose(%d)\n": "FD %s:%d sclose(%d)\n":
@ -435,30 +434,30 @@ void curl_mark_sclose(curl_socket_t sockfd, int line, const char *source)
"FD %s:%d sclose(%zd)\n"; "FD %s:%d sclose(%zd)\n";
if(source) if(source)
curl_memlog(fmt, source, line, sockfd); curl_dbg_log(fmt, source, line, sockfd);
} }
/* this is our own defined way to close sockets on *ALL* platforms */ /* this is our own defined way to close sockets on *ALL* platforms */
int curl_sclose(curl_socket_t sockfd, int line, const char *source) int curl_dbg_sclose(curl_socket_t sockfd, int line, const char *source)
{ {
int res = sclose(sockfd); int res = sclose(sockfd);
curl_mark_sclose(sockfd, line, source); curl_dbg_mark_sclose(sockfd, line, source);
return res; return res;
} }
FILE *curl_fopen(const char *file, const char *mode, FILE *curl_dbg_fopen(const char *file, const char *mode,
int line, const char *source) int line, const char *source)
{ {
FILE *res = fopen(file, mode); FILE *res = fopen(file, mode);
if(source) if(source)
curl_memlog("FILE %s:%d fopen(\"%s\",\"%s\") = %p\n", curl_dbg_log("FILE %s:%d fopen(\"%s\",\"%s\") = %p\n",
source, line, file, mode, (void *)res); source, line, file, mode, (void *)res);
return res; return res;
} }
int curl_fclose(FILE *file, int line, const char *source) int curl_dbg_fclose(FILE *file, int line, const char *source)
{ {
int res; int res;
@ -467,7 +466,7 @@ int curl_fclose(FILE *file, int line, const char *source)
res = fclose(file); res = fclose(file);
if(source) if(source)
curl_memlog("FILE %s:%d fclose(%p)\n", curl_dbg_log("FILE %s:%d fclose(%p)\n",
source, line, (void *)file); source, line, (void *)file);
return res; return res;
@ -476,13 +475,13 @@ int curl_fclose(FILE *file, int line, const char *source)
#define LOGLINE_BUFSIZE 1024 #define LOGLINE_BUFSIZE 1024
/* this does the writing to the memory tracking log file */ /* this does the writing to the memory tracking log file */
void curl_memlog(const char *format, ...) void curl_dbg_log(const char *format, ...)
{ {
char *buf; char *buf;
int nchars; int nchars;
va_list ap; va_list ap;
if(!logfile) if(!curl_dbg_logfile)
return; return;
buf = (Curl_cmalloc)(LOGLINE_BUFSIZE); buf = (Curl_cmalloc)(LOGLINE_BUFSIZE);
@ -497,7 +496,7 @@ void curl_memlog(const char *format, ...)
nchars = LOGLINE_BUFSIZE - 1; nchars = LOGLINE_BUFSIZE - 1;
if(nchars > 0) if(nchars > 0)
fwrite(buf, 1, (size_t)nchars, logfile); fwrite(buf, 1, (size_t)nchars, curl_dbg_logfile);
(Curl_cfree)(buf); (Curl_cfree)(buf);
} }

View File

@ -30,93 +30,92 @@
#define CURL_MT_LOGFNAME_BUFSIZE 512 #define CURL_MT_LOGFNAME_BUFSIZE 512
#define logfile curl_debuglogfile extern FILE *curl_dbg_logfile;
extern FILE *logfile;
/* memory functions */ /* memory functions */
CURL_EXTERN void *curl_domalloc(size_t size, int line, const char *source); CURL_EXTERN void *curl_dbg_malloc(size_t size, int line, const char *source);
CURL_EXTERN void *curl_docalloc(size_t elements, size_t size, int line, CURL_EXTERN void *curl_dbg_calloc(size_t elements, size_t size, int line,
const char *source); const char *source);
CURL_EXTERN void *curl_dorealloc(void *ptr, size_t size, int line, CURL_EXTERN void *curl_dbg_realloc(void *ptr, size_t size, int line,
const char *source);
CURL_EXTERN void curl_dofree(void *ptr, int line, const char *source);
CURL_EXTERN char *curl_dostrdup(const char *str, int line, const char *source);
#if defined(WIN32) && defined(UNICODE)
CURL_EXTERN wchar_t *curl_dowcsdup(const wchar_t *str, int line,
const char *source); const char *source);
CURL_EXTERN void curl_dbg_free(void *ptr, int line, const char *source);
CURL_EXTERN char *curl_dbg_strdup(const char *str, int line, const char *src);
#if defined(WIN32) && defined(UNICODE)
CURL_EXTERN wchar_t *curl_dbg_wcsdup(const wchar_t *str, int line,
const char *source);
#endif #endif
CURL_EXTERN void curl_memdebug(const char *logname); CURL_EXTERN void curl_dbg_memdebug(const char *logname);
CURL_EXTERN void curl_memlimit(long limit); CURL_EXTERN void curl_dbg_memlimit(long limit);
CURL_EXTERN void curl_memlog(const char *format, ...); CURL_EXTERN void curl_dbg_log(const char *format, ...);
/* file descriptor manipulators */ /* file descriptor manipulators */
CURL_EXTERN curl_socket_t curl_socket(int domain, int type, int protocol, CURL_EXTERN curl_socket_t curl_dbg_socket(int domain, int type, int protocol,
int line, const char *source);
CURL_EXTERN void curl_dbg_mark_sclose(curl_socket_t sockfd,
int line, const char *source); int line, const char *source);
CURL_EXTERN void curl_mark_sclose(curl_socket_t sockfd, CURL_EXTERN int curl_dbg_sclose(curl_socket_t sockfd,
int line, const char *source);
CURL_EXTERN int curl_sclose(curl_socket_t sockfd,
int line, const char *source);
CURL_EXTERN curl_socket_t curl_accept(curl_socket_t s, void *a, void *alen,
int line, const char *source);
#ifdef HAVE_SOCKETPAIR
CURL_EXTERN int curl_socketpair(int domain, int type, int protocol,
curl_socket_t socket_vector[2],
int line, const char *source); int line, const char *source);
CURL_EXTERN curl_socket_t curl_dbg_accept(curl_socket_t s, void *a, void *alen,
int line, const char *source);
#ifdef HAVE_SOCKETPAIR
CURL_EXTERN int curl_dbg_socketpair(int domain, int type, int protocol,
curl_socket_t socket_vector[2],
int line, const char *source);
#endif #endif
/* send/receive sockets */ /* send/receive sockets */
CURL_EXTERN SEND_TYPE_RETV curl_dosend(SEND_TYPE_ARG1 sockfd, CURL_EXTERN SEND_TYPE_RETV curl_dbg_send(SEND_TYPE_ARG1 sockfd,
SEND_QUAL_ARG2 SEND_TYPE_ARG2 buf, SEND_QUAL_ARG2 SEND_TYPE_ARG2 buf,
SEND_TYPE_ARG3 len, SEND_TYPE_ARG3 len,
SEND_TYPE_ARG4 flags, int line, SEND_TYPE_ARG4 flags, int line,
const char *source); const char *source);
CURL_EXTERN RECV_TYPE_RETV curl_dorecv(RECV_TYPE_ARG1 sockfd, CURL_EXTERN RECV_TYPE_RETV curl_dbg_recv(RECV_TYPE_ARG1 sockfd,
RECV_TYPE_ARG2 buf, RECV_TYPE_ARG3 len, RECV_TYPE_ARG2 buf,
RECV_TYPE_ARG4 flags, int line, RECV_TYPE_ARG3 len,
const char *source); RECV_TYPE_ARG4 flags, int line,
const char *source);
/* FILE functions */ /* FILE functions */
CURL_EXTERN FILE *curl_fopen(const char *file, const char *mode, int line, CURL_EXTERN FILE *curl_dbg_fopen(const char *file, const char *mode, int line,
const char *source); const char *source);
CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source); CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
#ifndef MEMDEBUG_NODEFINES #ifndef MEMDEBUG_NODEFINES
/* Set this symbol on the command-line, recompile all lib-sources */ /* Set this symbol on the command-line, recompile all lib-sources */
#undef strdup #undef strdup
#define strdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__) #define strdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__)
#define malloc(size) curl_domalloc(size, __LINE__, __FILE__) #define malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__)
#define calloc(nbelem,size) curl_docalloc(nbelem, size, __LINE__, __FILE__) #define calloc(nbelem,size) curl_dbg_calloc(nbelem, size, __LINE__, __FILE__)
#define realloc(ptr,size) curl_dorealloc(ptr, size, __LINE__, __FILE__) #define realloc(ptr,size) curl_dbg_realloc(ptr, size, __LINE__, __FILE__)
#define free(ptr) curl_dofree(ptr, __LINE__, __FILE__) #define free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__)
#define send(a,b,c,d) curl_dosend(a,b,c,d, __LINE__, __FILE__) #define send(a,b,c,d) curl_dbg_send(a,b,c,d, __LINE__, __FILE__)
#define recv(a,b,c,d) curl_dorecv(a,b,c,d, __LINE__, __FILE__) #define recv(a,b,c,d) curl_dbg_recv(a,b,c,d, __LINE__, __FILE__)
#ifdef WIN32 #ifdef WIN32
# ifdef UNICODE # ifdef UNICODE
# undef wcsdup # undef wcsdup
# define wcsdup(ptr) curl_dowcsdup(ptr, __LINE__, __FILE__) # define wcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__)
# undef _wcsdup # undef _wcsdup
# define _wcsdup(ptr) curl_dowcsdup(ptr, __LINE__, __FILE__) # define _wcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__)
# undef _tcsdup # undef _tcsdup
# define _tcsdup(ptr) curl_dowcsdup(ptr, __LINE__, __FILE__) # define _tcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__)
# else # else
# undef _tcsdup # undef _tcsdup
# define _tcsdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__) # define _tcsdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__)
# endif # endif
#endif #endif
#undef socket #undef socket
#define socket(domain,type,protocol)\ #define socket(domain,type,protocol)\
curl_socket(domain, type, protocol, __LINE__, __FILE__) curl_dbg_socket(domain, type, protocol, __LINE__, __FILE__)
#undef accept /* for those with accept as a macro */ #undef accept /* for those with accept as a macro */
#define accept(sock,addr,len)\ #define accept(sock,addr,len)\
curl_accept(sock, addr, len, __LINE__, __FILE__) curl_dbg_accept(sock, addr, len, __LINE__, __FILE__)
#ifdef HAVE_SOCKETPAIR #ifdef HAVE_SOCKETPAIR
#define socketpair(domain,type,protocol,socket_vector)\ #define socketpair(domain,type,protocol,socket_vector)\
curl_socketpair(domain, type, protocol, socket_vector, __LINE__, __FILE__) curl_dbg_socketpair(domain, type, protocol, socket_vector, __LINE__, __FILE__)
#endif #endif
#ifdef HAVE_GETADDRINFO #ifdef HAVE_GETADDRINFO
@ -125,31 +124,31 @@ CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
our macro as for other platforms. Instead, we redefine the new name they our macro as for other platforms. Instead, we redefine the new name they
define getaddrinfo to become! */ define getaddrinfo to become! */
#define ogetaddrinfo(host,serv,hint,res) \ #define ogetaddrinfo(host,serv,hint,res) \
curl_dogetaddrinfo(host, serv, hint, res, __LINE__, __FILE__) curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
#else #else
#undef getaddrinfo #undef getaddrinfo
#define getaddrinfo(host,serv,hint,res) \ #define getaddrinfo(host,serv,hint,res) \
curl_dogetaddrinfo(host, serv, hint, res, __LINE__, __FILE__) curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
#endif #endif
#endif /* HAVE_GETADDRINFO */ #endif /* HAVE_GETADDRINFO */
#ifdef HAVE_FREEADDRINFO #ifdef HAVE_FREEADDRINFO
#undef freeaddrinfo #undef freeaddrinfo
#define freeaddrinfo(data) \ #define freeaddrinfo(data) \
curl_dofreeaddrinfo(data, __LINE__, __FILE__) curl_dbg_freeaddrinfo(data, __LINE__, __FILE__)
#endif /* HAVE_FREEADDRINFO */ #endif /* HAVE_FREEADDRINFO */
/* sclose is probably already defined, redefine it! */ /* sclose is probably already defined, redefine it! */
#undef sclose #undef sclose
#define sclose(sockfd) curl_sclose(sockfd,__LINE__,__FILE__) #define sclose(sockfd) curl_dbg_sclose(sockfd,__LINE__,__FILE__)
#define fake_sclose(sockfd) curl_mark_sclose(sockfd,__LINE__,__FILE__) #define fake_sclose(sockfd) curl_dbg_mark_sclose(sockfd,__LINE__,__FILE__)
#undef fopen #undef fopen
#define fopen(file,mode) curl_fopen(file,mode,__LINE__,__FILE__) #define fopen(file,mode) curl_dbg_fopen(file,mode,__LINE__,__FILE__)
#undef fdopen #undef fdopen
#define fdopen(file,mode) curl_fdopen(file,mode,__LINE__,__FILE__) #define fdopen(file,mode) curl_dbg_fdopen(file,mode,__LINE__,__FILE__)
#define fclose(file) curl_fclose(file,__LINE__,__FILE__) #define fclose(file) curl_dbg_fclose(file,__LINE__,__FILE__)
#endif /* MEMDEBUG_NODEFINES */ #endif /* MEMDEBUG_NODEFINES */

View File

@ -145,22 +145,6 @@ my %api = (
# the following funcions are provided globally in debug builds # the following funcions are provided globally in debug builds
'curl_easy_perform_ev' => 'debug-build', 'curl_easy_perform_ev' => 'debug-build',
'curl_memdebug' => 'debug-build',
'curl_memlimit' => 'debug-build',
'curl_memlog' => 'debug-build',
'curl_accept' => 'debug-build',
'curl_docalloc' => 'debug-build',
'curl_dofree' => 'debug-build',
'curl_domalloc' => 'debug-build',
'curl_dorealloc' => 'debug-build',
'curl_dorecv' => 'debug-build',
'curl_dosend' => 'debug-build',
'curl_dostrdup' => 'debug-build',
'curl_fclose' => 'debug-build',
'curl_fopen' => 'debug-build',
'curl_sclose' => 'debug-build',
'curl_socket' => 'debug-build',
'curl_socketpair' => 'debug-build',
); );
open(N, "nm $file|") || open(N, "nm $file|") ||
@ -202,6 +186,9 @@ for(sort keys %exist) {
$err++; $err++;
} }
} }
elsif($_ =~ /^curl_dbg_/) {
# we ignore the memdebug symbols
}
elsif($wl{$_}) { elsif($wl{$_}) {
#print "$_ is WL\n"; #print "$_ is WL\n";
} }

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -112,7 +112,7 @@ static void memory_tracking_init(void)
env[CURL_MT_LOGFNAME_BUFSIZE-1] = '\0'; env[CURL_MT_LOGFNAME_BUFSIZE-1] = '\0';
strcpy(fname, env); strcpy(fname, env);
curl_free(env); curl_free(env);
curl_memdebug(fname); curl_dbg_memdebug(fname);
/* this weird stuff here is to make curl_free() get called /* this weird stuff here is to make curl_free() get called
before curl_memdebug() as otherwise memory tracking will before curl_memdebug() as otherwise memory tracking will
log a free() without an alloc! */ log a free() without an alloc! */
@ -123,7 +123,7 @@ static void memory_tracking_init(void)
char *endptr; char *endptr;
long num = strtol(env, &endptr, 10); long num = strtol(env, &endptr, 10);
if((endptr != env) && (endptr == env + strlen(env)) && (num > 0)) if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
curl_memlimit(num); curl_dbg_memlimit(num);
curl_free(env); curl_free(env);
} }
} }

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -96,7 +96,7 @@ static void memory_tracking_init(void)
env[CURL_MT_LOGFNAME_BUFSIZE-1] = '\0'; env[CURL_MT_LOGFNAME_BUFSIZE-1] = '\0';
strcpy(fname, env); strcpy(fname, env);
curl_free(env); curl_free(env);
curl_memdebug(fname); curl_dbg_memdebug(fname);
/* this weird stuff here is to make curl_free() get called /* this weird stuff here is to make curl_free() get called
before curl_memdebug() as otherwise memory tracking will before curl_memdebug() as otherwise memory tracking will
log a free() without an alloc! */ log a free() without an alloc! */
@ -107,7 +107,7 @@ static void memory_tracking_init(void)
char *endptr; char *endptr;
long num = strtol(env, &endptr, 10); long num = strtol(env, &endptr, 10);
if((endptr != env) && (endptr == env + strlen(env)) && (num > 0)) if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
curl_memlimit(num); curl_dbg_memlimit(num);
curl_free(env); curl_free(env);
} }
} }