13
0
geforkt von Mirrors/Velocity

Try to diagnose memory leak

Dieser Commit ist enthalten in:
Andrew Steinborn 2019-12-31 21:43:02 -05:00
Ursprung 2073d79771
Commit 08df080771
2 geänderte Dateien mit 8 neuen und 25 gelöschten Zeilen

Datei anzeigen

@ -22,7 +22,6 @@ public class MinecraftCipherDecoder extends MessageToMessageDecoder<ByteBuf> {
try { try {
cipher.process(compatible); cipher.process(compatible);
out.add(compatible); out.add(compatible);
in.skipBytes(in.readableBytes());
} catch (Exception e) { } catch (Exception e) {
compatible.release(); // compatible will never be used if we throw an exception compatible.release(); // compatible will never be used if we throw an exception
throw e; throw e;

Datei anzeigen

@ -4,38 +4,22 @@ import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.CorruptedFrameException;
import java.util.List; import java.util.List;
public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder { public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder {
@Override @Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
read_lens: while (in.isReadable()) { while (in.isReadable()) {
int origReaderIndex = in.readerIndex(); int ri = in.readerIndex();
for (int i = 0; i < 3; i++) {
if (!in.isReadable()) {
in.readerIndex(origReaderIndex);
return;
}
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); int packetLength = ProtocolUtils.readVarInt(in);
if (in.readableBytes() >= packetLength) { if (in.readableBytes() >= packetLength) {
out.add(in.readRetainedSlice(packetLength)); out.add(in.readBytes(packetLength));
continue read_lens;
} else { } else {
in.readerIndex(origReaderIndex); in.readerIndex(ri);
return; break;
} }
} }
} }
throw new CorruptedFrameException("VarInt too big");
}
}
} }