This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new e513f073e1 Review "Fix use-after-return of pooled send buffer in async
sends"
e513f073e1 is described below
commit e513f073e1b5a554523ad861c82b083f4ccafde2
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Oct 21 10:24:21 2026 +0100
Review "Fix use-after-return of pooled send buffer in async sends"
Make shallow clone more efficient
Co-authored by: CoPilot / GPT-5.6 Sol
---
java/org/apache/catalina/tribes/io/ChannelData.java | 5 +++--
test/org/apache/catalina/tribes/io/TestChannelData.java | 11 +++++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/java/org/apache/catalina/tribes/io/ChannelData.java
b/java/org/apache/catalina/tribes/io/ChannelData.java
index 0f798c8d85..8a59467fe8 100644
--- a/java/org/apache/catalina/tribes/io/ChannelData.java
+++ b/java/org/apache/catalina/tribes/io/ChannelData.java
@@ -329,8 +329,9 @@ public class ChannelData implements ChannelMessage {
clone.uniqueId = this.uniqueId.clone();
}
if (this.message != null) {
- clone.message = new XByteBuffer(this.message.getBytesDirect(),
false);
- clone.message.setLength(this.message.getLength());
+ int messageLength = this.message.getLength();
+ clone.message = new XByteBuffer(messageLength, false);
+ clone.message.append(this.message.getBytesDirect(), 0,
messageLength);
}
return clone;
}
diff --git a/test/org/apache/catalina/tribes/io/TestChannelData.java
b/test/org/apache/catalina/tribes/io/TestChannelData.java
index 9f6a3967bb..4f1993154a 100644
--- a/test/org/apache/catalina/tribes/io/TestChannelData.java
+++ b/test/org/apache/catalina/tribes/io/TestChannelData.java
@@ -24,10 +24,21 @@ public class TestChannelData {
@Test
public void testClone() {
ChannelData original = new ChannelData();
+ byte[] payload = new byte[] { 1, 2, 3, 4 };
+ XByteBuffer message = new XByteBuffer(1024, false);
+ message.append(payload, 0, payload.length);
+ original.setMessage(message);
+
ChannelData clone = original.clone();
Assert.assertFalse(original == clone);
Assert.assertTrue(original.getClass() == clone.getClass());
Assert.assertTrue(original.equals(clone));
+ Assert.assertNotSame(message, clone.getMessage());
+ Assert.assertArrayEquals(payload, clone.getMessage().getBytes());
+ Assert.assertEquals(payload.length, clone.getMessage().getCapacity());
+
+ message.getBytesDirect()[0] = 99;
+ Assert.assertEquals(1, clone.getMessage().getBytesDirect()[0]);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]