commit d5d9357fbbe6b697a01c76d009cbefb2b9a72c32
parent 92867501a5acaba877e6d6a5b749dcdd4c266dc5
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Mon, 20 Jul 2026 18:27:04 +0200
MHD_response_from_buffer(): call cleanup on failure
Diffstat:
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h
@@ -6435,8 +6435,9 @@ MHD_response_from_callback_2cls (enum MHD_HTTP_StatusCode sc,
* when response is being destroyed, can be NULL
* to skip the free/cleanup callback;
* @param free_cb_cls the parameter for @a free_cb
- * @return NULL on error (i.e. invalid arguments, out of memory)
- * on error, @a free_cb is NOT called
+ * @return new response object on success,
+ * NULL on failure (i.e. invalid arguments, out of memory),
+ * @p free_cb is called automatically in case of failure
* @ingroup response
*/
MHD_EXTERN_ struct MHD_Response *
diff --git a/src/include/microhttpd2_main.h.in b/src/include/microhttpd2_main.h.in
@@ -1518,8 +1518,9 @@ MHD_response_from_callback_2cls (enum MHD_HTTP_StatusCode sc,
* when response is being destroyed, can be NULL
* to skip the free/cleanup callback;
* @param free_cb_cls the parameter for @a free_cb
- * @return NULL on error (i.e. invalid arguments, out of memory)
- * on error, @a free_cb is NOT called
+ * @return new response object on success,
+ * NULL on failure (i.e. invalid arguments, out of memory),
+ * @p free_cb is called automatically in case of failure
* @ingroup response
*/
MHD_EXTERN_ struct MHD_Response *
diff --git a/src/mhd2/response_from.c b/src/mhd2/response_from.c
@@ -168,7 +168,11 @@ MHD_response_from_buffer (
#if SIZEOF_SIZE_T >= 8
if (MHD_SIZE_UNKNOWN == buffer_size)
+ {
+ if (NULL != free_cb)
+ free_cb (free_cb_cls);
return NULL;
+ }
#endif /* SIZEOF_SIZE_T >= 8 */
res = response_create_basic (sc, buffer_size, free_cb, free_cb_cls);
@@ -178,6 +182,8 @@ MHD_response_from_buffer (
res->cntn.buf = (0 != buffer_size) ?
(const unsigned char *)buffer : empty_buf;
}
+ else if (NULL != free_cb)
+ free_cb (free_cb_cls);
return res;
}