1 #ifndef HEADER_CURL_MEMDEBUG_H 2 #define HEADER_CURL_MEMDEBUG_H 3 #ifdef CURLDEBUG 4 /*************************************************************************** 5 * _ _ ____ _ 6 * Project ___| | | | _ \| | 7 * / __| | | | |_) | | 8 * | (__| |_| | _ <| |___ 9 * \___|\___/|_| \_\_____| 10 * 11 * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. 12 * 13 * This software is licensed as described in the file COPYING, which 14 * you should have received as part of this distribution. The terms 15 * are also available at http://curl.haxx.se/docs/copyright.html. 16 * 17 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 18 * copies of the Software, and permit persons to whom the Software is 19 * furnished to do so, under the terms of the COPYING file. 20 * 21 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 22 * KIND, either express or implied. 23 * 24 ***************************************************************************/ 25 26 /* 27 * CAUTION: this header is designed to work when included by the app-side 28 * as well as the library. Do not mix with library internals! 29 */ 30 31 #include "curl_setup.h" 32 33 #include <curl/curl.h> 34 35 #define CURL_MT_LOGFNAME_BUFSIZE 512 36 37 #define logfile curl_debuglogfile 38 39 extern FILE *logfile; 40 41 /* memory functions */ 42 CURL_EXTERN void *curl_domalloc(size_t size, int line, const char *source); 43 CURL_EXTERN void *curl_docalloc(size_t elements, size_t size, int line, 44 const char *source); 45 CURL_EXTERN void *curl_dorealloc(void *ptr, size_t size, int line, 46 const char *source); 47 CURL_EXTERN void curl_dofree(void *ptr, int line, const char *source); 48 CURL_EXTERN char *curl_dostrdup(const char *str, int line, const char *source); 49 #if defined(WIN32) && defined(UNICODE) 50 CURL_EXTERN wchar_t *curl_dowcsdup(const wchar_t *str, int line, 51 const char *source); 52 #endif 53 54 CURL_EXTERN void curl_memdebug(const char *logname); 55 CURL_EXTERN void curl_memlimit(long limit); 56 CURL_EXTERN void curl_memlog(const char *format, ...); 57 58 /* file descriptor manipulators */ 59 CURL_EXTERN curl_socket_t curl_socket(int domain, int type, int protocol, 60 int line , const char *source); 61 CURL_EXTERN void curl_mark_sclose(curl_socket_t sockfd, 62 int line , const char *source); 63 CURL_EXTERN int curl_sclose(curl_socket_t sockfd, 64 int line , const char *source); 65 CURL_EXTERN curl_socket_t curl_accept(curl_socket_t s, void *a, void *alen, 66 int line, const char *source); 67 #ifdef HAVE_SOCKETPAIR 68 CURL_EXTERN int curl_socketpair(int domain, int type, int protocol, 69 curl_socket_t socket_vector[2], 70 int line , const char *source); 71 #endif 72 73 /* FILE functions */ 74 CURL_EXTERN FILE *curl_fopen(const char *file, const char *mode, int line, 75 const char *source); 76 #ifdef HAVE_FDOPEN 77 CURL_EXTERN FILE *curl_fdopen(int filedes, const char *mode, int line, 78 const char *source); 79 #endif 80 CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source); 81 82 #ifndef MEMDEBUG_NODEFINES 83 84 /* Set this symbol on the command-line, recompile all lib-sources */ 85 #undef strdup 86 #define strdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__) 87 #define malloc(size) curl_domalloc(size, __LINE__, __FILE__) 88 #define calloc(nbelem,size) curl_docalloc(nbelem, size, __LINE__, __FILE__) 89 #define realloc(ptr,size) curl_dorealloc(ptr, size, __LINE__, __FILE__) 90 #define free(ptr) curl_dofree(ptr, __LINE__, __FILE__) 91 92 #ifdef WIN32 93 # ifdef UNICODE 94 # undef wcsdup 95 # define wcsdup(ptr) curl_dowcsdup(ptr, __LINE__, __FILE__) 96 # undef _wcsdup 97 # define _wcsdup(ptr) curl_dowcsdup(ptr, __LINE__, __FILE__) 98 # undef _tcsdup 99 # define _tcsdup(ptr) curl_dowcsdup(ptr, __LINE__, __FILE__) 100 # else 101 # undef _tcsdup 102 # define _tcsdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__) 103 # endif 104 #endif 105 106 #define socket(domain,type,protocol)\ 107 curl_socket(domain, type, protocol, __LINE__, __FILE__) 108 #undef accept /* for those with accept as a macro */ 109 #define accept(sock,addr,len)\ 110 curl_accept(sock, addr, len, __LINE__, __FILE__) 111 #ifdef HAVE_SOCKETPAIR 112 #define socketpair(domain,type,protocol,socket_vector)\ 113 curl_socketpair(domain, type, protocol, socket_vector, __LINE__, __FILE__) 114 #endif 115 116 #ifdef HAVE_GETADDRINFO 117 #if defined(getaddrinfo) && defined(__osf__) 118 /* OSF/1 and Tru64 have getaddrinfo as a define already, so we cannot define 119 our macro as for other platforms. Instead, we redefine the new name they 120 define getaddrinfo to become! */ 121 #define ogetaddrinfo(host,serv,hint,res) \ 122 curl_dogetaddrinfo(host, serv, hint, res, __LINE__, __FILE__) 123 #else 124 #undef getaddrinfo 125 #define getaddrinfo(host,serv,hint,res) \ 126 curl_dogetaddrinfo(host, serv, hint, res, __LINE__, __FILE__) 127 #endif 128 #endif /* HAVE_GETADDRINFO */ 129 130 #ifdef HAVE_GETNAMEINFO 131 #undef getnameinfo 132 #define getnameinfo(sa,salen,host,hostlen,serv,servlen,flags) \ 133 curl_dogetnameinfo(sa, salen, host, hostlen, serv, servlen, flags, \ 134 __LINE__, __FILE__) 135 #endif /* HAVE_GETNAMEINFO */ 136 137 #ifdef HAVE_FREEADDRINFO 138 #undef freeaddrinfo 139 #define freeaddrinfo(data) \ 140 curl_dofreeaddrinfo(data, __LINE__, __FILE__) 141 #endif /* HAVE_FREEADDRINFO */ 142 143 /* sclose is probably already defined, redefine it! */ 144 #undef sclose 145 #define sclose(sockfd) curl_sclose(sockfd,__LINE__,__FILE__) 146 147 #define fake_sclose(sockfd) curl_mark_sclose(sockfd,__LINE__,__FILE__) 148 149 #undef fopen 150 #define fopen(file,mode) curl_fopen(file,mode,__LINE__,__FILE__) 151 #undef fdopen 152 #define fdopen(file,mode) curl_fdopen(file,mode,__LINE__,__FILE__) 153 #define fclose(file) curl_fclose(file,__LINE__,__FILE__) 154 155 #endif /* MEMDEBUG_NODEFINES */ 156 157 #endif /* CURLDEBUG */ 158 159 /* 160 ** Following section applies even when CURLDEBUG is not defined. 161 */ 162 163 #ifndef fake_sclose 164 #define fake_sclose(x) Curl_nop_stmt 165 #endif 166 167 /* 168 * Curl_safefree defined as a macro to allow MemoryTracking feature 169 * to log free() calls at same location where Curl_safefree is used. 170 * This macro also assigns NULL to given pointer when free'd. 171 */ 172 173 #define Curl_safefree(ptr) \ 174 do { free((ptr)); (ptr) = NULL;} WHILE_FALSE 175 176 #endif /* HEADER_CURL_MEMDEBUG_H */ 177