LOG4J2-1296 trim reusable message StringBuilder to 258 to ensure occasional 
very long messages do not result in large char[] arrays being held by the 
RingBuffer forever


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/69999c22
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/69999c22
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/69999c22

Branch: refs/heads/LOG4J2-1116
Commit: 69999c2278bbefdace942ea5de9683226c14b5fe
Parents: 05adeef
Author: rpopma <rpo...@apache.org>
Authored: Tue Mar 15 03:10:31 2016 +1100
Committer: rpopma <rpo...@apache.org>
Committed: Tue Mar 15 03:10:31 2016 +1100

----------------------------------------------------------------------
 .../apache/logging/log4j/core/async/RingBufferLogEvent.java    | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/69999c22/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
index e918500..32d73d9 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
@@ -338,6 +338,12 @@ public class RingBufferLogEvent implements LogEvent {
                 null,
                 0, 0 // nanoTime
         );
+
+        // ensure that excessively long char[] arrays are not kept in memory 
forever
+        if (messageText != null && messageText.length() > 258) { // resized 
more than once from 128 (s=s*2+2)
+            messageText.setLength(258);
+            messageText.trimToSize();
+        }
     }
 
     private void writeObject(final java.io.ObjectOutputStream out) throws 
IOException {

Reply via email to