From 2b15f2e919050db647c49172769f067095128124 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 19 Jun 2021 13:19:08 -0400 Subject: [PATCH] Changes to make Velocity more amenable to memory leak detection --- proxy/src/main/java/com/velocitypowered/proxy/Velocity.java | 5 ++--- .../proxy/protocol/netty/MinecraftVarintFrameDecoder.java | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java b/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java index 2362a4df7..a75239eda 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/Velocity.java @@ -52,10 +52,9 @@ public class Velocity { System.setProperty("io.netty.native.workdir", System.getProperty("velocity.natives-tmpdir")); } - // Disable the resource leak detector by default as it reduces performance. Allow the user to - // override this if desired. + // Set the ADVANCED level of the leak detector. Time to go hunting. if (System.getProperty("io.netty.leakDetection.level") == null) { - ResourceLeakDetector.setLevel(Level.DISABLED); + ResourceLeakDetector.setLevel(Level.ADVANCED); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java index d81f53f5b..90d3f4039 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java @@ -59,7 +59,7 @@ public class MinecraftVarintFrameDecoder extends ByteToMessageDecoder { } else { int minimumRead = bytesRead + readVarint; if (in.isReadable(minimumRead)) { - out.add(in.retainedSlice(varintEnd + 1, readVarint)); + out.add(in.copy(varintEnd + 1, readVarint)); in.skipBytes(minimumRead); } }