From 2fcccef0c499c0a0931bf1d57f4c51b0f05e5943 Mon Sep 17 00:00:00 2001 From: Ludovic Orban Date: Tue, 22 Aug 2023 11:23:42 +0200 Subject: [PATCH] #10226 fix GZIPContentDecoder buffer leak of zero-capacity buffers Signed-off-by: Ludovic Orban --- .../main/java/org/eclipse/jetty/http/GZIPContentDecoder.java | 3 +++ .../main/java/org/eclipse/jetty/io/RetainableByteBuffer.java | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/GZIPContentDecoder.java b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/GZIPContentDecoder.java index a03b8f7430c..45c41eda497 100644 --- a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/GZIPContentDecoder.java +++ b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/GZIPContentDecoder.java @@ -422,6 +422,9 @@ public class GZIPContentDecoder implements Destroyable */ public RetainableByteBuffer acquire(int capacity) { + // Zero-capacity buffers aren't released, they MUST NOT come from the pool. + if (capacity == 0) + return RetainableByteBuffer.EMPTY; return _pool.acquire(capacity, false); } } diff --git a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/RetainableByteBuffer.java b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/RetainableByteBuffer.java index f59a7e6bdda..e1098d5191d 100644 --- a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/RetainableByteBuffer.java +++ b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/RetainableByteBuffer.java @@ -36,6 +36,11 @@ import org.eclipse.jetty.util.BufferUtil; */ public interface RetainableByteBuffer extends Retainable { + /** + * A Zero-capacity, non-retainable {@code RetainableByteBuffer}. + */ + public static RetainableByteBuffer EMPTY = wrap(BufferUtil.EMPTY_BUFFER); + /** *

Returns a non-retainable {@code RetainableByteBuffer} that wraps * the given {@code ByteBuffer}.