2011-07-26 19:23:27 +04:00
|
|
|
#ifndef HEADER_CURL_MEMDEBUG_H
|
|
|
|
#define HEADER_CURL_MEMDEBUG_H
|
2011-09-02 21:40:53 +04:00
|
|
|
#ifdef CURLDEBUG
|
2002-09-03 15:52:59 +04:00
|
|
|
/***************************************************************************
|
2004-11-09 17:00:56 +03:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
2002-03-19 10:54:55 +03:00
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2020-07-27 13:44:19 +03:00
|
|
|
* Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2002-03-19 10:54:55 +03:00
|
|
|
*
|
2002-09-03 15:52:59 +04:00
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 16:02:01 +03:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2004-11-09 17:00:56 +03:00
|
|
|
*
|
2002-03-19 10:54:55 +03:00
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
2002-09-03 15:52:59 +04:00
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
2002-03-19 10:54:55 +03:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
2011-09-02 21:40:53 +04:00
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 12:16:50 +03:00
|
|
|
*
|
2002-09-03 15:52:59 +04:00
|
|
|
***************************************************************************/
|
2000-12-19 16:23:54 +03:00
|
|
|
|
2004-02-18 15:18:33 +03:00
|
|
|
/*
|
|
|
|
* CAUTION: this header is designed to work when included by the app-side
|
|
|
|
* as well as the library. Do not mix with library internals!
|
|
|
|
*/
|
|
|
|
|
2022-09-07 13:19:29 +03:00
|
|
|
#include <curl/curl.h>
|
|
|
|
|
2022-08-13 17:17:12 +03:00
|
|
|
#if defined(__GNUC__) && __GNUC__ >= 3
|
|
|
|
# define ALLOC_FUNC __attribute__((malloc))
|
|
|
|
# define ALLOC_SIZE(s) __attribute__((alloc_size(s)))
|
|
|
|
# define ALLOC_SIZE2(n, s) __attribute__((alloc_size(n, s)))
|
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
# define ALLOC_FUNC __declspec(restrict)
|
|
|
|
# define ALLOC_SIZE(s)
|
|
|
|
# define ALLOC_SIZE2(n, s)
|
|
|
|
#else
|
|
|
|
# define ALLOC_FUNC
|
|
|
|
# define ALLOC_SIZE(s)
|
|
|
|
# define ALLOC_SIZE2(n, s)
|
|
|
|
#endif
|
|
|
|
|
2011-08-20 19:26:02 +04:00
|
|
|
#define CURL_MT_LOGFNAME_BUFSIZE 512
|
|
|
|
|
2019-03-08 12:47:29 +03:00
|
|
|
extern FILE *curl_dbg_logfile;
|
2001-10-04 17:25:12 +04:00
|
|
|
|
2000-12-14 18:56:59 +03:00
|
|
|
/* memory functions */
|
2022-08-13 17:17:12 +03:00
|
|
|
CURL_EXTERN ALLOC_FUNC ALLOC_SIZE(1) void *curl_dbg_malloc(size_t size,
|
|
|
|
int line,
|
|
|
|
const char *source);
|
|
|
|
CURL_EXTERN ALLOC_FUNC ALLOC_SIZE2(1, 2) void *curl_dbg_calloc(size_t elements,
|
|
|
|
size_t size, int line, const char *source);
|
|
|
|
CURL_EXTERN ALLOC_SIZE(2) void *curl_dbg_realloc(void *ptr,
|
|
|
|
size_t size,
|
|
|
|
int line,
|
|
|
|
const char *source);
|
2019-03-08 12:47:29 +03:00
|
|
|
CURL_EXTERN void curl_dbg_free(void *ptr, int line, const char *source);
|
2022-08-13 17:17:12 +03:00
|
|
|
CURL_EXTERN ALLOC_FUNC char *curl_dbg_strdup(const char *str, int line,
|
|
|
|
const char *src);
|
2019-03-08 12:47:29 +03:00
|
|
|
#if defined(WIN32) && defined(UNICODE)
|
2022-08-13 17:17:12 +03:00
|
|
|
CURL_EXTERN ALLOC_FUNC wchar_t *curl_dbg_wcsdup(const wchar_t *str,
|
|
|
|
int line,
|
|
|
|
const char *source);
|
2013-07-18 22:04:02 +04:00
|
|
|
#endif
|
|
|
|
|
2019-03-08 12:47:29 +03:00
|
|
|
CURL_EXTERN void curl_dbg_memdebug(const char *logname);
|
|
|
|
CURL_EXTERN void curl_dbg_memlimit(long limit);
|
|
|
|
CURL_EXTERN void curl_dbg_log(const char *format, ...);
|
2000-10-09 15:11:43 +04:00
|
|
|
|
2000-12-14 18:56:59 +03:00
|
|
|
/* file descriptor manipulators */
|
2019-03-08 12:47:29 +03:00
|
|
|
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,
|
2016-04-03 21:28:34 +03:00
|
|
|
int line, const char *source);
|
2019-03-08 12:47:29 +03:00
|
|
|
CURL_EXTERN int curl_dbg_sclose(curl_socket_t sockfd,
|
2016-04-03 21:28:34 +03:00
|
|
|
int line, const char *source);
|
2019-03-08 12:47:29 +03:00
|
|
|
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);
|
2011-07-29 15:25:52 +04:00
|
|
|
#endif
|
2000-12-14 18:56:59 +03:00
|
|
|
|
2017-10-10 17:56:35 +03:00
|
|
|
/* send/receive sockets */
|
2019-03-08 12:47:29 +03:00
|
|
|
CURL_EXTERN SEND_TYPE_RETV curl_dbg_send(SEND_TYPE_ARG1 sockfd,
|
|
|
|
SEND_QUAL_ARG2 SEND_TYPE_ARG2 buf,
|
|
|
|
SEND_TYPE_ARG3 len,
|
|
|
|
SEND_TYPE_ARG4 flags, int line,
|
|
|
|
const char *source);
|
|
|
|
CURL_EXTERN RECV_TYPE_RETV curl_dbg_recv(RECV_TYPE_ARG1 sockfd,
|
|
|
|
RECV_TYPE_ARG2 buf,
|
|
|
|
RECV_TYPE_ARG3 len,
|
|
|
|
RECV_TYPE_ARG4 flags, int line,
|
|
|
|
const char *source);
|
2017-10-10 17:56:35 +03:00
|
|
|
|
2000-12-19 16:23:54 +03:00
|
|
|
/* FILE functions */
|
2022-08-13 17:17:12 +03:00
|
|
|
CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fopen(const char *file, const char *mode,
|
2020-07-27 13:44:19 +03:00
|
|
|
int line, const char *source);
|
2022-08-13 17:17:12 +03:00
|
|
|
CURL_EXTERN ALLOC_FUNC FILE *curl_dbg_fdopen(int filedes, const char *mode,
|
|
|
|
int line, const char *source);
|
2020-07-27 13:44:19 +03:00
|
|
|
|
2019-03-08 12:47:29 +03:00
|
|
|
CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
|
2000-12-19 16:23:54 +03:00
|
|
|
|
2004-01-29 16:56:45 +03:00
|
|
|
#ifndef MEMDEBUG_NODEFINES
|
|
|
|
|
2000-10-09 15:11:43 +04:00
|
|
|
/* Set this symbol on the command-line, recompile all lib-sources */
|
2002-10-28 22:20:59 +03:00
|
|
|
#undef strdup
|
2019-03-08 12:47:29 +03:00
|
|
|
#define strdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__)
|
|
|
|
#define malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__)
|
|
|
|
#define calloc(nbelem,size) curl_dbg_calloc(nbelem, size, __LINE__, __FILE__)
|
|
|
|
#define realloc(ptr,size) curl_dbg_realloc(ptr, size, __LINE__, __FILE__)
|
|
|
|
#define free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__)
|
|
|
|
#define send(a,b,c,d) curl_dbg_send(a,b,c,d, __LINE__, __FILE__)
|
|
|
|
#define recv(a,b,c,d) curl_dbg_recv(a,b,c,d, __LINE__, __FILE__)
|
2000-12-14 18:56:59 +03:00
|
|
|
|
2013-07-18 22:04:02 +04:00
|
|
|
#ifdef WIN32
|
|
|
|
# ifdef UNICODE
|
2013-07-19 08:44:46 +04:00
|
|
|
# undef wcsdup
|
2019-03-08 12:47:29 +03:00
|
|
|
# define wcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__)
|
2013-07-19 08:44:46 +04:00
|
|
|
# undef _wcsdup
|
2019-03-08 12:47:29 +03:00
|
|
|
# define _wcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__)
|
2013-07-19 08:44:46 +04:00
|
|
|
# undef _tcsdup
|
2019-03-08 12:47:29 +03:00
|
|
|
# define _tcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__)
|
2013-07-18 22:04:02 +04:00
|
|
|
# else
|
2013-07-19 08:44:46 +04:00
|
|
|
# undef _tcsdup
|
2019-03-08 12:47:29 +03:00
|
|
|
# define _tcsdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__)
|
2013-07-18 22:04:02 +04:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2015-12-07 22:27:29 +03:00
|
|
|
#undef socket
|
2000-12-14 18:56:59 +03:00
|
|
|
#define socket(domain,type,protocol)\
|
2019-03-08 12:47:29 +03:00
|
|
|
curl_dbg_socket(domain, type, protocol, __LINE__, __FILE__)
|
2004-02-03 00:34:01 +03:00
|
|
|
#undef accept /* for those with accept as a macro */
|
2000-12-18 19:13:37 +03:00
|
|
|
#define accept(sock,addr,len)\
|
2019-03-08 12:47:29 +03:00
|
|
|
curl_dbg_accept(sock, addr, len, __LINE__, __FILE__)
|
2011-07-29 15:25:52 +04:00
|
|
|
#ifdef HAVE_SOCKETPAIR
|
|
|
|
#define socketpair(domain,type,protocol,socket_vector)\
|
2019-03-08 12:47:29 +03:00
|
|
|
curl_dbg_socketpair(domain, type, protocol, socket_vector, __LINE__, __FILE__)
|
2011-07-29 15:25:52 +04:00
|
|
|
#endif
|
2000-12-14 18:56:59 +03:00
|
|
|
|
2008-10-30 22:02:23 +03:00
|
|
|
#ifdef HAVE_GETADDRINFO
|
2005-06-30 17:28:58 +04:00
|
|
|
#if defined(getaddrinfo) && defined(__osf__)
|
|
|
|
/* OSF/1 and Tru64 have getaddrinfo as a define already, so we cannot define
|
|
|
|
our macro as for other platforms. Instead, we redefine the new name they
|
|
|
|
define getaddrinfo to become! */
|
|
|
|
#define ogetaddrinfo(host,serv,hint,res) \
|
2019-03-08 12:47:29 +03:00
|
|
|
curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
|
2005-06-30 17:28:58 +04:00
|
|
|
#else
|
2005-11-14 02:53:14 +03:00
|
|
|
#undef getaddrinfo
|
2001-10-04 17:25:12 +04:00
|
|
|
#define getaddrinfo(host,serv,hint,res) \
|
2019-03-08 12:47:29 +03:00
|
|
|
curl_dbg_getaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
|
2005-06-30 17:28:58 +04:00
|
|
|
#endif
|
2008-10-30 22:02:23 +03:00
|
|
|
#endif /* HAVE_GETADDRINFO */
|
2006-07-04 06:27:11 +04:00
|
|
|
|
2008-10-30 22:02:23 +03:00
|
|
|
#ifdef HAVE_FREEADDRINFO
|
2005-11-14 02:53:14 +03:00
|
|
|
#undef freeaddrinfo
|
2001-10-04 17:25:12 +04:00
|
|
|
#define freeaddrinfo(data) \
|
2019-03-08 12:47:29 +03:00
|
|
|
curl_dbg_freeaddrinfo(data, __LINE__, __FILE__)
|
2008-10-30 22:02:23 +03:00
|
|
|
#endif /* HAVE_FREEADDRINFO */
|
2001-10-04 17:25:12 +04:00
|
|
|
|
2000-12-14 18:56:59 +03:00
|
|
|
/* sclose is probably already defined, redefine it! */
|
|
|
|
#undef sclose
|
2019-03-08 12:47:29 +03:00
|
|
|
#define sclose(sockfd) curl_dbg_sclose(sockfd,__LINE__,__FILE__)
|
2000-12-14 18:56:59 +03:00
|
|
|
|
2019-03-08 12:47:29 +03:00
|
|
|
#define fake_sclose(sockfd) curl_dbg_mark_sclose(sockfd,__LINE__,__FILE__)
|
2009-10-28 23:30:23 +03:00
|
|
|
|
2000-12-19 16:23:54 +03:00
|
|
|
#undef fopen
|
2019-03-08 12:47:29 +03:00
|
|
|
#define fopen(file,mode) curl_dbg_fopen(file,mode,__LINE__,__FILE__)
|
2007-06-28 15:11:29 +04:00
|
|
|
#undef fdopen
|
2019-03-08 12:47:29 +03:00
|
|
|
#define fdopen(file,mode) curl_dbg_fdopen(file,mode,__LINE__,__FILE__)
|
|
|
|
#define fclose(file) curl_dbg_fclose(file,__LINE__,__FILE__)
|
2000-12-19 16:23:54 +03:00
|
|
|
|
2004-01-29 16:56:45 +03:00
|
|
|
#endif /* MEMDEBUG_NODEFINES */
|
|
|
|
|
2004-02-18 15:18:33 +03:00
|
|
|
#endif /* CURLDEBUG */
|
2009-10-28 23:30:23 +03:00
|
|
|
|
2011-09-02 21:40:53 +04:00
|
|
|
/*
|
|
|
|
** Following section applies even when CURLDEBUG is not defined.
|
|
|
|
*/
|
|
|
|
|
2009-10-28 23:30:23 +03:00
|
|
|
#ifndef fake_sclose
|
2011-09-03 18:06:10 +04:00
|
|
|
#define fake_sclose(x) Curl_nop_stmt
|
2009-10-28 23:30:23 +03:00
|
|
|
#endif
|
2011-09-02 21:40:53 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Curl_safefree defined as a macro to allow MemoryTracking feature
|
|
|
|
* to log free() calls at same location where Curl_safefree is used.
|
2011-09-15 19:35:23 +04:00
|
|
|
* This macro also assigns NULL to given pointer when free'd.
|
2011-09-02 21:40:53 +04:00
|
|
|
*/
|
|
|
|
|
2011-09-15 19:35:23 +04:00
|
|
|
#define Curl_safefree(ptr) \
|
2019-11-30 11:29:36 +03:00
|
|
|
do { free((ptr)); (ptr) = NULL;} while(0)
|
2011-09-02 21:40:53 +04:00
|
|
|
|
|
|
|
#endif /* HEADER_CURL_MEMDEBUG_H */
|