From a76c8a7b944e43f56ddbcac0b49832a0d7f91d8b Mon Sep 17 00:00:00 2001 From: Andrew Clayton Date: Fri, 22 Aug 2025 17:47:21 +0100 Subject: http: compression: brotli: Don't leak memory on error Signed-off-by: Andrew Clayton --- src/nxt_brotli.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/nxt_brotli.c b/src/nxt_brotli.c index 773b8b6f..c69d977e 100644 --- a/src/nxt_brotli.c +++ b/src/nxt_brotli.c @@ -46,14 +46,14 @@ nxt_brotli_compress(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf, &in_len, &in_buf, &out_bytes, &out_buf, NULL); if (!ok) { - return -1; + goto out_err_free; } ok = BrotliEncoderCompressStream(brotli, BROTLI_OPERATION_FLUSH, &in_len, &in_buf, &out_bytes, &out_buf, NULL); if (!ok) { - return -1; + goto out_err_free; } if (last) { @@ -61,13 +61,18 @@ nxt_brotli_compress(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf, &in_len, &in_buf, &out_bytes, &out_buf, NULL); if (!ok) { - return -1; + goto out_err_free; } BrotliEncoderDestroyInstance(brotli); } return out_len - out_bytes; + +out_err_free: + BrotliEncoderDestroyInstance(brotli); + + return -1; } -- cgit