mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
the malloc debug system only logs data if the logfile FILE * is set, which
makes it easier to disable debug output when built with debug functions
This commit is contained in:
parent
db0e3cc60c
commit
010044e03c
22
lib/hostip.c
22
lib/hostip.c
@ -96,21 +96,27 @@ int curl_getaddrinfo(char *hostname, char *service,
|
|||||||
int line, const char *source)
|
int line, const char *source)
|
||||||
{
|
{
|
||||||
int res=(getaddrinfo)(hostname, service, hints, result);
|
int res=(getaddrinfo)(hostname, service, hints, result);
|
||||||
if(0 == res)
|
if(0 == res) {
|
||||||
/* success */
|
/* success */
|
||||||
fprintf(logfile?logfile:stderr, "ADDR %s:%d getaddrinfo() = %p\n",
|
if(logfile)
|
||||||
source, line, *result);
|
fprintf(logfile, "ADDR %s:%d getaddrinfo() = %p\n",
|
||||||
else
|
source, line, *result);
|
||||||
fprintf(logfile?logfile:stderr, "ADDR %s:%d getaddrinfo() failed\n",
|
}
|
||||||
source, line);
|
else {
|
||||||
|
if(logfile)
|
||||||
|
fprintf(logfile, "ADDR %s:%d getaddrinfo() failed\n",
|
||||||
|
source, line);
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void curl_freeaddrinfo(struct addrinfo *freethis,
|
void curl_freeaddrinfo(struct addrinfo *freethis,
|
||||||
int line, const char *source)
|
int line, const char *source)
|
||||||
{
|
{
|
||||||
(freeaddrinfo)(freethis);
|
(freeaddrinfo)(freethis);
|
||||||
fprintf(logfile?logfile:stderr, "ADDR %s:%d freeaddrinfo(%p)\n",
|
if(logfile)
|
||||||
source, line, freethis);
|
fprintf(logfile, "ADDR %s:%d freeaddrinfo(%p)\n",
|
||||||
|
source, line, freethis);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -60,15 +60,19 @@ FILE *logfile;
|
|||||||
/* this sets the log file name */
|
/* this sets the log file name */
|
||||||
void curl_memdebug(const char *logname)
|
void curl_memdebug(const char *logname)
|
||||||
{
|
{
|
||||||
logfile = fopen(logname, "w");
|
if(logname)
|
||||||
|
logfile = fopen(logname, "w");
|
||||||
|
else
|
||||||
|
logfile = stderr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *curl_domalloc(size_t size, int line, const char *source)
|
void *curl_domalloc(size_t size, int line, const char *source)
|
||||||
{
|
{
|
||||||
void *mem=(malloc)(size);
|
void *mem=(malloc)(size);
|
||||||
fprintf(logfile?logfile:stderr, "MEM %s:%d malloc(%d) = %p\n",
|
if(logfile)
|
||||||
source, line, size, mem);
|
fprintf(logfile, "MEM %s:%d malloc(%d) = %p\n",
|
||||||
|
source, line, size, mem);
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,16 +89,18 @@ char *curl_dostrdup(const char *str, int line, const char *source)
|
|||||||
|
|
||||||
mem=(strdup)(str);
|
mem=(strdup)(str);
|
||||||
len=strlen(str)+1;
|
len=strlen(str)+1;
|
||||||
fprintf(logfile?logfile:stderr, "MEM %s:%d strdup(%p) (%d) = %p\n",
|
if(logfile)
|
||||||
source, line, str, len, mem);
|
fprintf(logfile, "MEM %s:%d strdup(%p) (%d) = %p\n",
|
||||||
|
source, line, str, len, mem);
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *curl_dorealloc(void *ptr, size_t size, int line, const char *source)
|
void *curl_dorealloc(void *ptr, size_t size, int line, const char *source)
|
||||||
{
|
{
|
||||||
void *mem=(realloc)(ptr, size);
|
void *mem=(realloc)(ptr, size);
|
||||||
fprintf(logfile?logfile:stderr, "MEM %s:%d realloc(%p, %d) = %p\n",
|
if(logfile)
|
||||||
source, line, ptr, size, mem);
|
fprintf(logfile, "MEM %s:%d realloc(%p, %d) = %p\n",
|
||||||
|
source, line, ptr, size, mem);
|
||||||
return mem;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,15 +114,16 @@ void curl_dofree(void *ptr, int line, const char *source)
|
|||||||
|
|
||||||
(free)(ptr);
|
(free)(ptr);
|
||||||
|
|
||||||
fprintf(logfile?logfile:stderr, "MEM %s:%d free(%p)\n",
|
if(logfile)
|
||||||
source, line, ptr);
|
fprintf(logfile, "MEM %s:%d free(%p)\n", source, line, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int curl_socket(int domain, int type, int protocol, int line, char *source)
|
int curl_socket(int domain, int type, int protocol, int line, char *source)
|
||||||
{
|
{
|
||||||
int sockfd=(socket)(domain, type, protocol);
|
int sockfd=(socket)(domain, type, protocol);
|
||||||
fprintf(logfile?logfile:stderr, "FD %s:%d socket() = %d\n",
|
if(logfile)
|
||||||
source, line, sockfd);
|
fprintf(logfile, "FD %s:%d socket() = %d\n",
|
||||||
|
source, line, sockfd);
|
||||||
return sockfd;
|
return sockfd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,8 +131,9 @@ int curl_accept(int s, struct sockaddr *addr, socklen_t *addrlen,
|
|||||||
int line, const char *source)
|
int line, const char *source)
|
||||||
{
|
{
|
||||||
int sockfd=(accept)(s, addr, addrlen);
|
int sockfd=(accept)(s, addr, addrlen);
|
||||||
fprintf(logfile?logfile:stderr, "FD %s:%d accept() = %d\n",
|
if(logfile)
|
||||||
source, line, sockfd);
|
fprintf(logfile, "FD %s:%d accept() = %d\n",
|
||||||
|
source, line, sockfd);
|
||||||
return sockfd;
|
return sockfd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,8 +141,9 @@ int curl_accept(int s, struct sockaddr *addr, socklen_t *addrlen,
|
|||||||
int curl_sclose(int sockfd, int line, char *source)
|
int curl_sclose(int sockfd, int line, char *source)
|
||||||
{
|
{
|
||||||
int res=sclose(sockfd);
|
int res=sclose(sockfd);
|
||||||
fprintf(logfile?logfile:stderr, "FD %s:%d sclose(%d)\n",
|
if(logfile)
|
||||||
source, line, sockfd);
|
fprintf(logfile, "FD %s:%d sclose(%d)\n",
|
||||||
|
source, line, sockfd);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,16 +151,18 @@ FILE *curl_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);
|
||||||
fprintf(logfile?logfile:stderr, "FILE %s:%d fopen(\"%s\") = %p\n",
|
if(logfile)
|
||||||
source, line, file, res);
|
fprintf(logfile, "FILE %s:%d fopen(\"%s\") = %p\n",
|
||||||
|
source, line, file, res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int curl_fclose(FILE *file, int line, const char *source)
|
int curl_fclose(FILE *file, int line, const char *source)
|
||||||
{
|
{
|
||||||
int res=(fclose)(file);
|
int res=(fclose)(file);
|
||||||
fprintf(logfile?logfile:stderr, "FILE %s:%d fclose(%p)\n",
|
if(logfile)
|
||||||
source, line, file);
|
fprintf(logfile, "FILE %s:%d fclose(%p)\n",
|
||||||
|
source, line, file);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user