curl/lib/memdebug.h
Daniel Stenberg ae647a7941
tests: strict torture mode, warn on alloc after limit
In order to better track down cases where we don't exit cleanly and
directly on OOM errors, this mode warns if there is another memory
operation found *after* the torture limit was reached.

runtests sets this strict mode.

memdebug adds two new helper functions needed to make this work.

curl_dbg_overlook() lets the code mark a memory allocation as fine to
not notice and yet do another one after even if this one returns error.

curl_dbg_restart() marks the code as - at this point the code ignores
the OOM status and it is fine to do another memory call afterwards
without it being considered a problem.
2025-11-24 08:17:49 +01:00

59 lines
2.1 KiB
C

#ifndef HEADER_CURL_MEMDEBUG_H
#define HEADER_CURL_MEMDEBUG_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* 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
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
/*
* CAUTION: this header is designed to work when included by the app-side
* as well as the library. Do not mix with library internals!
*/
#ifdef CURLDEBUG
/* Set this symbol on the command-line, recompile all lib-sources */
#undef strdup
#define strdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__)
#undef malloc
#define malloc(size) curl_dbg_malloc(size, __LINE__, __FILE__)
#undef calloc
#define calloc(nbelem,size) curl_dbg_calloc(nbelem, size, __LINE__, __FILE__)
#undef realloc
#define realloc(ptr,size) curl_dbg_realloc(ptr, size, __LINE__, __FILE__)
#undef free
#define free(ptr) curl_dbg_free(ptr, __LINE__, __FILE__)
#ifdef _WIN32
#undef Curl_tcsdup
#ifdef UNICODE
#define Curl_tcsdup(ptr) curl_dbg_wcsdup(ptr, __LINE__, __FILE__)
#else
#define Curl_tcsdup(ptr) curl_dbg_strdup(ptr, __LINE__, __FILE__)
#endif
#endif /* _WIN32 */
#define curl_dbg_overlook(x) curl_dbg_allow(__LINE__, __FILE__, x)
#define curl_dbg_restart() curl_dbg_clear(__LINE__, __FILE__)
#endif /* CURLDEBUG */
#endif /* HEADER_CURL_MEMDEBUG_H */