-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix memory leak in CustomPayloadS2CPacket
This is technically a bug in vanilla, however vanilla is saved from this bug due to pure dumb luck: it extensively abuses unpooled heap buffers, so the buffer just gets picked up by the garbage collector and we have nothing to worry about. However, with pooled direct buffers (as with Krypton), the copy is a big problem since it will occupy precious direct buffer space. Worse still, the copy isn't even needed at all. Change it to a slice, which is what it should've been in the first place. While we're at it, add a new mixin to allow the resource leak detection level to be changed via the normal system property.
- Loading branch information
Showing
4 changed files
with
38 additions
and
6 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
...va/me/steinborn/krypton/mixin/shared/bugfix/CustomPayloadS2CPacketFixMemoryLeakMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package me.steinborn.krypton.mixin.shared.bugfix; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import net.minecraft.network.PacketByteBuf; | ||
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@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(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
.../steinborn/krypton/mixin/shared/debugaid/ResourceLeakDetectorDisableConditionalMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package me.steinborn.krypton.mixin.shared.debugaid; | ||
|
||
import io.netty.util.ResourceLeakDetector; | ||
import net.minecraft.SharedConstants; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(SharedConstants.class) | ||
public class ResourceLeakDetectorDisableConditionalMixin { | ||
@Redirect(method = "<clinit>", at = @At(value = "INVOKE", target = "Lio/netty/util/ResourceLeakDetector;setLevel(Lio/netty/util/ResourceLeakDetector$Level;)V")) | ||
private static void clinit$resourceLeakDetectorDisableConditional(ResourceLeakDetector.Level level) { | ||
if (System.getProperty("io.netty.leakDetection.level") == null) { | ||
// Allow the user to override the leak detection level in the Minecraft server with the | ||
// io.netty.leakDetection.level system property. | ||
ResourceLeakDetector.setLevel(level); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters