Fix ByteBuf leak in Js5ResponseDecoder

Signed-off-by: Graham <gpe@openrs2.org>
Graham 4 years ago
parent e1404a1f7f
commit 6a800c0759
  1. 12
      protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoder.kt

@ -78,6 +78,7 @@ public class Js5ResponseDecoder : ByteToMessageDecoder() {
data.writeBytes(input, blockLen) data.writeBytes(input, blockLen)
if (!last && input.readUnsignedByte().toInt() != 0xFF) { if (!last && input.readUnsignedByte().toInt() != 0xFF) {
reset()
throw DecoderException("Invalid block trailer") throw DecoderException("Invalid block trailer")
} }
} }
@ -90,8 +91,19 @@ public class Js5ResponseDecoder : ByteToMessageDecoder() {
} }
} }
override fun channelInactive(ctx: ChannelHandlerContext) {
super.channelInactive(ctx)
reset()
}
override fun handlerRemoved0(ctx: ChannelHandlerContext?) { override fun handlerRemoved0(ctx: ChannelHandlerContext?) {
reset()
}
private fun reset() {
data.release() data.release()
data = Unpooled.EMPTY_BUFFER data = Unpooled.EMPTY_BUFFER
state = State.READ_HEADER
} }
} }

Loading…
Cancel
Save