From 6a800c07591332b43c803b6614167bc4b2f55df9 Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 1 Nov 2020 14:31:25 +0000 Subject: [PATCH] Fix ByteBuf leak in Js5ResponseDecoder Signed-off-by: Graham --- .../org/openrs2/protocol/js5/Js5ResponseDecoder.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoder.kt b/protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoder.kt index 5e4fe156..888eb07c 100644 --- a/protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoder.kt +++ b/protocol/src/main/kotlin/org/openrs2/protocol/js5/Js5ResponseDecoder.kt @@ -78,6 +78,7 @@ public class Js5ResponseDecoder : ByteToMessageDecoder() { data.writeBytes(input, blockLen) if (!last && input.readUnsignedByte().toInt() != 0xFF) { + reset() 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?) { + reset() + } + + private fun reset() { data.release() data = Unpooled.EMPTY_BUFFER + + state = State.READ_HEADER } }