This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push: new 3ed7483 Discard large byte buffers on request recycle 3ed7483 is described below commit 3ed74837215700081a5917d4d871f973dd27745a Author: remm <r...@apache.org> AuthorDate: Thu Jul 18 00:32:38 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 | 10 ++++++++++ webapps/docs/changelog.xml | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/java/org/apache/catalina/connector/OutputBuffer.java b/java/org/apache/catalina/connector/OutputBuffer.java index 22c8fa3..5fa8fc2 100644 --- a/java/org/apache/catalina/connector/OutputBuffer.java +++ b/java/org/apache/catalina/connector/OutputBuffer.java @@ -58,6 +58,11 @@ public class OutputBuffer extends Writer { private final Map<Charset, C2BConverter> encoders = new HashMap<>(); + /** + * Default buffer size. + */ + private final int defaultBufferSize; + // ----------------------------------------------------- Instance Variables /** @@ -128,6 +133,7 @@ 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); @@ -188,6 +194,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 af61944..20dea22 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