From 90d1cc409e68285140c3d1a38a79f4b708e4c1f7 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Wed, 9 Mar 2022 00:31:29 -0500 Subject: [PATCH] Fix the memory leak in a different way Specifically, the way vanilla works. --- .../bugfix/CustomPayloadS2CPacketFixMemoryLeakMixin.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/steinborn/krypton/mixin/shared/bugfix/CustomPayloadS2CPacketFixMemoryLeakMixin.java b/src/main/java/me/steinborn/krypton/mixin/shared/bugfix/CustomPayloadS2CPacketFixMemoryLeakMixin.java index a2c2680..b76b79c 100644 --- a/src/main/java/me/steinborn/krypton/mixin/shared/bugfix/CustomPayloadS2CPacketFixMemoryLeakMixin.java +++ b/src/main/java/me/steinborn/krypton/mixin/shared/bugfix/CustomPayloadS2CPacketFixMemoryLeakMixin.java @@ -1,6 +1,7 @@ package me.steinborn.krypton.mixin.shared.bugfix; import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; import org.spongepowered.asm.mixin.Mixin; @@ -10,8 +11,8 @@ @Mixin(CustomPayloadS2CPacket.class) public class CustomPayloadS2CPacketFixMemoryLeakMixin { - @Redirect(method = "getData", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketByteBuf;copy()Lio/netty/buffer/ByteBuf;")) - private ByteBuf getData$copyShouldBeSlice(PacketByteBuf instance) { - return instance.slice(); + @Redirect(method = "(Lnet/minecraft/network/PacketByteBuf;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketByteBuf;readBytes(I)Lio/netty/buffer/ByteBuf;")) + private ByteBuf getData$copyShouldBeSlice(PacketByteBuf instance, int length) { + return Unpooled.copiedBuffer(instance.readSlice(length)); } }