From 08df0807717579f5858f08423d0e821cc43cc08a Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Tue, 31 Dec 2019 21:43:02 -0500 Subject: [PATCH] Try to diagnose memory leak --- .../netty/MinecraftCipherDecoder.java | 1 - .../netty/MinecraftVarintFrameDecoder.java | 32 +++++-------------- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherDecoder.java index ad02191e7..3eca73b4b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherDecoder.java @@ -22,7 +22,6 @@ public class MinecraftCipherDecoder extends MessageToMessageDecoder { try { cipher.process(compatible); out.add(compatible); - in.skipBytes(in.readableBytes()); } catch (Exception e) { compatible.release(); // compatible will never be used if we throw an exception throw e; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java index b003fc48c..c8fec71a9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java @@ -4,38 +4,22 @@ import com.velocitypowered.proxy.protocol.ProtocolUtils; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; -import io.netty.handler.codec.CorruptedFrameException; import java.util.List; public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder { @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { - read_lens: while (in.isReadable()) { - int origReaderIndex = in.readerIndex(); - for (int i = 0; i < 3; i++) { - if (!in.isReadable()) { - in.readerIndex(origReaderIndex); - return; - } + while (in.isReadable()) { + int ri = in.readerIndex(); + int packetLength = ProtocolUtils.readVarInt(in); - byte read = in.readByte(); - if (read >= 0) { - // Make sure reader index of length buffer is returned to the beginning - in.readerIndex(origReaderIndex); - int packetLength = ProtocolUtils.readVarInt(in); - - if (in.readableBytes() >= packetLength) { - out.add(in.readRetainedSlice(packetLength)); - continue read_lens; - } else { - in.readerIndex(origReaderIndex); - return; - } - } + if (in.readableBytes() >= packetLength) { + out.add(in.readBytes(packetLength)); + } else { + in.readerIndex(ri); + break; } - - throw new CorruptedFrameException("VarInt too big"); } } }