From 03fc499566fd80c6eb5055cea7c505c21537997f Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 25 May 2021 21:32:56 +0100 Subject: [PATCH] Improve robustness of reference counting in JaggrabChannelHandler Signed-off-by: Graham --- .../game/net/jaggrab/JaggrabChannelHandler.kt | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/game/src/main/kotlin/org/openrs2/game/net/jaggrab/JaggrabChannelHandler.kt b/game/src/main/kotlin/org/openrs2/game/net/jaggrab/JaggrabChannelHandler.kt index e80d81155e..72b71df23e 100644 --- a/game/src/main/kotlin/org/openrs2/game/net/jaggrab/JaggrabChannelHandler.kt +++ b/game/src/main/kotlin/org/openrs2/game/net/jaggrab/JaggrabChannelHandler.kt @@ -4,6 +4,7 @@ import io.netty.channel.ChannelFutureListener import io.netty.channel.ChannelHandler import io.netty.channel.ChannelHandlerContext import io.netty.channel.SimpleChannelInboundHandler +import org.openrs2.buffer.use import org.openrs2.game.net.FileProvider import org.openrs2.protocol.jaggrab.JaggrabRequest import javax.inject.Inject @@ -19,13 +20,14 @@ public class JaggrabChannelHandler @Inject constructor( } override fun channelRead0(ctx: ChannelHandlerContext, msg: JaggrabRequest) { - val file = fileProvider.get(msg.path) - if (file == null) { - ctx.close() - return - } + fileProvider.get(msg.path).use { file -> + if (file == null) { + ctx.close() + return + } - ctx.write(file).addListener(ChannelFutureListener.CLOSE) + ctx.write(file.retain()).addListener(ChannelFutureListener.CLOSE) + } } override fun channelReadComplete(ctx: ChannelHandlerContext) {