You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by ru...@apache.org on 2020/12/31 03:25:19 UTC
[incubator-ratis] branch master updated: RATIS-1278. Resource leak
when decoding DataStreamReplyByteBuffer. (#388)
This is an automated email from the ASF dual-hosted git repository.
runzhiwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ratis.git
The following commit(s) were added to refs/heads/master by this push:
new b6fbb50 RATIS-1278. Resource leak when decoding DataStreamReplyByteBuffer. (#388)
b6fbb50 is described below
commit b6fbb50e22cd04001690f473ebb15f74a8b09e32
Author: Tsz-Wo Nicholas Sze <sz...@apache.org>
AuthorDate: Thu Dec 31 11:25:12 2020 +0800
RATIS-1278. Resource leak when decoding DataStreamReplyByteBuffer. (#388)
---
.../main/java/org/apache/ratis/netty/NettyDataStreamUtils.java | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/ratis-netty/src/main/java/org/apache/ratis/netty/NettyDataStreamUtils.java b/ratis-netty/src/main/java/org/apache/ratis/netty/NettyDataStreamUtils.java
index c35da3e..1f4f7c5 100644
--- a/ratis-netty/src/main/java/org/apache/ratis/netty/NettyDataStreamUtils.java
+++ b/ratis-netty/src/main/java/org/apache/ratis/netty/NettyDataStreamUtils.java
@@ -119,12 +119,18 @@ public interface NettyDataStreamUtils {
.orElse(null);
}
+ static ByteBuffer copy(ByteBuf buf) {
+ final byte[] bytes = new byte[buf.readableBytes()];
+ buf.readBytes(bytes);
+ return ByteBuffer.wrap(bytes);
+ }
+
static DataStreamReplyByteBuffer decodeDataStreamReplyByteBuffer(ByteBuf buf) {
return Optional.ofNullable(DataStreamReplyHeader.read(buf))
.map(header -> checkHeader(header, buf))
.map(header -> DataStreamReplyByteBuffer.newBuilder()
.setDataStreamReplyHeader(header)
- .setBuffer(decodeData(buf, header, b -> b.copy().nioBuffer()))
+ .setBuffer(decodeData(buf, header, NettyDataStreamUtils::copy))
.build())
.orElse(null);
}