commit 556f775124fa444d2d0f5992d2105b9fd26810f5
parent 6b6a0fa7ec9029c28791bf29c284ee7fba666a7a
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Mon, 20 Jul 2026 20:00:58 +0200
MHD_response_from_iovec(): call cleanup on failure
Diffstat:
3 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h
@@ -6537,8 +6537,9 @@ struct MHD_IoVec
* @param free_cb the callback to clean up any data associated with @a iov when
* the response is destroyed.
* @param free_cb_cls the argument passed to @a free_cb
- * @return NULL on error (i.e. invalid arguments, out of memory)
- * FIXME: Call free callback on error?
+ * @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
@@ -1620,8 +1620,9 @@ struct MHD_IoVec
* @param free_cb the callback to clean up any data associated with @a iov when
* the response is destroyed.
* @param free_cb_cls the argument passed to @a free_cb
- * @return NULL on error (i.e. invalid arguments, out of memory)
- * FIXME: Call free callback on error?
+ * @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
@@ -242,8 +242,8 @@ MHD_response_from_buffer_copy (
}
-MHD_EXTERN_ struct MHD_Response *
-MHD_response_from_iovec (
+static struct MHD_Response *
+response_from_iovec_inner (
enum MHD_HTTP_StatusCode sc,
unsigned int iov_count,
const struct MHD_IoVec iov[MHD_FN_PAR_DYN_ARR_SIZE_ (iov_count)],
@@ -352,6 +352,23 @@ MHD_response_from_iovec (
}
+MHD_EXTERN_ struct MHD_Response *
+MHD_response_from_iovec (
+ enum MHD_HTTP_StatusCode sc,
+ unsigned int iov_count,
+ const struct MHD_IoVec iov[MHD_FN_PAR_DYN_ARR_SIZE_ (iov_count)],
+ MHD_FreeCallback free_cb,
+ void *free_cb_cls)
+{
+ struct MHD_Response *res =
+ response_from_iovec_inner (sc, iov_count, iov, free_cb, free_cb_cls);
+ if ((NULL == res) && (NULL != free_cb))
+ free_cb (free_cb_cls);
+
+ return res;
+}
+
+
MHD_EXTERN_
MHD_FN_PAR_FD_READ_ (2) struct MHD_Response *
MHD_response_from_fd (enum MHD_HTTP_StatusCode sc,