This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new 5f03949 Discard large byte buffers on request recycle 5f03949 is described below commit 5f039493cf3f503eb279cddbd7d6d70a1d21ffc5 Author: remm <r...@apache.org> AuthorDate: Thu Jul 18 00:39:05 2019 +0200 Discard large byte buffers on request recycle With the ByteBuffer based code, buffers allocated when using setBufferSize with a large value would never be discarded. --- java/org/apache/catalina/connector/OutputBuffer.java | 12 ++++++++++-- webapps/docs/changelog.xml | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/java/org/apache/catalina/connector/OutputBuffer.java b/java/org/apache/catalina/connector/OutputBuffer.java index e23fa20..6e0e951 100644 --- a/java/org/apache/catalina/connector/OutputBuffer.java +++ b/java/org/apache/catalina/connector/OutputBuffer.java @@ -59,6 +59,11 @@ public class OutputBuffer extends Writer { private final Map<Charset, C2BConverter> encoders = new HashMap<>(); + /** + * Default buffer size. + */ + private final int defaultBufferSize; + // ----------------------------------------------------- Instance Variables /** @@ -146,12 +151,11 @@ public class OutputBuffer extends Writer { * @param size Buffer size to use */ public OutputBuffer(int size) { - + defaultBufferSize = size; bb = ByteBuffer.allocate(size); clear(bb); cb = CharBuffer.allocate(size); clear(cb); - } @@ -209,6 +213,10 @@ public class OutputBuffer extends Writer { bytesWritten = 0; charsWritten = 0; + if (bb.capacity() > 16 * defaultBufferSize) { + // Discard buffers which are too large + bb = ByteBuffer.allocate(defaultBufferSize); + } clear(bb); clear(cb); closed = false; diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 32774ff..696cddc 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -56,6 +56,10 @@ <code>AsyncContext.start(Runnable)</code>, process it using the standard error page mechanism. (markt) </fix> + <fix> + Discard large byte buffers allocated using setBufferSize when recycling + the request. (remm) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org