]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
multi: add handle asserts in DEBUG builds
authorStefan Eissing <stefan@eissing.org>
Wed, 22 Mar 2023 09:25:24 +0000 (10:25 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 22 Mar 2023 12:57:20 +0000 (13:57 +0100)
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

lib/multi.c
lib/urldata.h

index 731b2598f1c8b453032c71a9a9fb4eb4d327f024..262321d9d6d0d4908e12211e6c98af40b7c97cdf 100644 (file)
 
 #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);
index 8b54518d2004e93b38ccd621924f0923fa064367..86b3da71866ea3cdf67fbadf21d3cd2fa4b14b7c 100644 (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 */