libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

commit 92867501a5acaba877e6d6a5b749dcdd4c266dc5
parent 72942193bd154ecec8868ca9a15e1d7190588aad
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date:   Mon, 20 Jul 2026 15:58:16 +0200

MHD_response_from_callback_2cls(): call free_cb() on failure

Diffstat:
Msrc/include/microhttpd2.h | 9+++++----
Msrc/include/microhttpd2_main.h.in | 10++++++----
Msrc/mhd2/response_from.c | 2++
3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h @@ -6387,8 +6387,8 @@ typedef const struct MHD_DynamicContentCreatorAction * * can be NULL * @param free_cb_cls the parameter for @p free_cb * @return new response object on success, - * NULL on failure (i.e. invalid arguments, out of memory) - * FIXME: Call free callback on error? + * 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 * @@ -6410,8 +6410,9 @@ MHD_response_from_callback_2cls (enum MHD_HTTP_StatusCode sc, * @param dc extra argument to @p d, evaluated twice! * @param f callback to call to free @p dc resources * @return new response object on success, - * NULL on failure (i.e. invalid arguments, out of memory) - * FIXME: Call free callback on error? + * NULL on failure (i.e. invalid arguments, out of memory), + * the cleanup callback @p f is called automatically in case + * of failure * @warning The @p dc parameter is evaluated twice; avoid expressions * with side effects. Alternatively, just call function * #MHD_response_from_callback_2cls() directly. diff --git a/src/include/microhttpd2_main.h.in b/src/include/microhttpd2_main.h.in @@ -1469,8 +1469,8 @@ typedef const struct MHD_DynamicContentCreatorAction * * can be NULL * @param free_cb_cls the parameter for @p free_cb * @return new response object on success, - * NULL on failure (i.e. invalid arguments, out of memory) - * FIXME: Call free callback on error? + * 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 * @@ -1492,11 +1492,13 @@ MHD_response_from_callback_2cls (enum MHD_HTTP_StatusCode sc, * @param dc extra argument to @p d, evaluated twice! * @param f callback to call to free @p dc resources * @return new response object on success, - * NULL on failure (i.e. invalid arguments, out of memory) - * FIXME: Call free callback on error? + * NULL on failure (i.e. invalid arguments, out of memory), + * the cleanup callback @p f is called automatically in case + * of failure * @warning The @p dc parameter is evaluated twice; avoid expressions * with side effects. Alternatively, just call function * #MHD_response_from_callback_2cls() directly. + * #MHD_response_from_callback_2cls() directly. * @ingroup response */ #define MHD_response_from_callback(sc, s, d, dc, f) \ diff --git a/src/mhd2/response_from.c b/src/mhd2/response_from.c @@ -147,6 +147,8 @@ MHD_response_from_callback_2cls (enum MHD_HTTP_StatusCode sc, res->cntn.dyn.cb = dyn_cont; res->cntn.dyn.cls = dyn_cont_cls; } + else if (NULL != free_cb) + free_cb (free_cb_cls); return res; }