multi: add handle asserts in DEBUG builds

For GOOD_EASY_HANDLE and GOOD_MULTI_HANDLE checks

- allow NULL pointers to "just" return an error as before
- fail hard on nun-NULL pointers that no longer show the MAGICs

Closes #10812
This commit is contained in:
Stefan Eissing 2023-03-22 10:25:24 +01:00 committed by Daniel Stenberg
parent 8a83bda0a2
commit 5d1ecbcbd2
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
2 changed files with 18 additions and 0 deletions

View File

@ -90,8 +90,17 @@
#define CURL_MULTI_HANDLE 0x000bab1e
#ifdef DEBUGBUILD
/* On a debug build, we want to fail hard on multi handles that
* are not NULL, but no longer have the MAGIC touch. This gives
* us early warning on things only discovered by valgrind otherwise. */
#define GOOD_MULTI_HANDLE(x) \
(((x) && (x)->magic == CURL_MULTI_HANDLE)? TRUE: \
(DEBUGASSERT(!(x)), FALSE))
#else
#define GOOD_MULTI_HANDLE(x) \
((x) && (x)->magic == CURL_MULTI_HANDLE)
#endif
static CURLMcode singlesocket(struct Curl_multi *multi,
struct Curl_easy *data);

View File

@ -208,8 +208,17 @@ typedef CURLcode (*Curl_datastream)(struct Curl_easy *data,
#define UPLOADBUFFER_MIN CURL_MAX_WRITE_SIZE
#define CURLEASY_MAGIC_NUMBER 0xc0dedbadU
#ifdef DEBUGBUILD
/* On a debug build, we want to fail hard on easy handles that
* are not NULL, but no longer have the MAGIC touch. This gives
* us early warning on things only discovered by valgrind otherwise. */
#define GOOD_EASY_HANDLE(x) \
(((x) && ((x)->magic == CURLEASY_MAGIC_NUMBER))? TRUE: \
(DEBUGASSERT(!(x)), FALSE))
#else
#define GOOD_EASY_HANDLE(x) \
((x) && ((x)->magic == CURLEASY_MAGIC_NUMBER))
#endif
#ifdef HAVE_GSSAPI
/* Types needed for krb5-ftp connections */