diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java index 37d5224f640..d77d48c787e 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java @@ -319,7 +319,10 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http while (_parser.inContentState()) { boolean handled = parseRequestBuffer(); - if (handled || filled <= 0) + // Re-check the parser state after parsing to avoid filling, + // otherwise fillRequestBuffer() would acquire a ByteBuffer + // that may be leaked. + if (handled || filled <= 0 || !_parser.inContentState()) break; filled = fillRequestBuffer(); }