From 1f9a1cbefc164391642d8b42e597c14c39055c1e Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 17 Jul 2025 15:08:55 +0200 Subject: [PATCH] MINOR: applet: Improve applet API to take care of inbuf/outbuf alloc failures applet_get_inbuf() and applet_get_outbuf() functions were not testing if the buffers were available. So, the caller had to check them before calling one of these functions. It is not really handy. So now, these functions take care to have a fully usable buffer before returning. Otherwise NULL is returned. --- include/haproxy/applet.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/haproxy/applet.h b/include/haproxy/applet.h index 2b1a5af7f..6856a3b28 100644 --- a/include/haproxy/applet.h +++ b/include/haproxy/applet.h @@ -288,8 +288,11 @@ static inline void applet_expect_data(struct appctx *appctx) */ static inline struct buffer *applet_get_inbuf(struct appctx *appctx) { - if (appctx->flags & APPCTX_FL_INOUT_BUFS) + if (appctx->flags & APPCTX_FL_INOUT_BUFS) { + if (applet_fl_test(appctx, APPCTX_FL_INBLK_ALLOC) || !appctx_get_buf(appctx, &appctx->inbuf)) + return NULL; return &appctx->inbuf; + } else return sc_ob(appctx_sc(appctx)); } @@ -300,8 +303,12 @@ static inline struct buffer *applet_get_inbuf(struct appctx *appctx) */ static inline struct buffer *applet_get_outbuf(struct appctx *appctx) { - if (appctx->flags & APPCTX_FL_INOUT_BUFS) + if (appctx->flags & APPCTX_FL_INOUT_BUFS) { + if (applet_fl_test(appctx, APPCTX_FL_OUTBLK_ALLOC|APPCTX_FL_OUTBLK_FULL) || + !appctx_get_buf(appctx, &appctx->outbuf)) + return NULL; return &appctx->outbuf; + } else return sc_ib(appctx_sc(appctx)); } -- 2.47.2