From cc89a2a1e5a4ccd72d0848ca6c31469f044d8332 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Thu, 5 Nov 2020 20:04:31 -0500 Subject: [PATCH] We don't need to retain/release the mod list buffer in readModList --- .../forge/legacy/LegacyForgeUtil.java | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeUtil.java index 8d2c9d410..e43847ebc 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/forge/legacy/LegacyForgeUtil.java @@ -39,31 +39,25 @@ class LegacyForgeUtil { */ static List readModList(PluginMessage message) { Preconditions.checkNotNull(message, "message"); - Preconditions - .checkArgument(message.getChannel().equals(FORGE_LEGACY_HANDSHAKE_CHANNEL), + Preconditions.checkArgument(message.getChannel().equals(FORGE_LEGACY_HANDSHAKE_CHANNEL), "message is not a FML HS plugin message"); - ByteBuf byteBuf = message.content().retainedSlice(); - try { - byte discriminator = byteBuf.readByte(); + ByteBuf contents = message.content().slice(); + byte discriminator = contents.readByte(); + if (discriminator == MOD_LIST_DISCRIMINATOR) { + ImmutableList.Builder mods = ImmutableList.builder(); + int modCount = ProtocolUtils.readVarInt(contents); - if (discriminator == MOD_LIST_DISCRIMINATOR) { - ImmutableList.Builder mods = ImmutableList.builder(); - int modCount = ProtocolUtils.readVarInt(byteBuf); - - for (int index = 0; index < modCount; index++) { - String id = ProtocolUtils.readString(byteBuf); - String version = ProtocolUtils.readString(byteBuf); - mods.add(new ModInfo.Mod(id, version)); - } - - return mods.build(); + for (int index = 0; index < modCount; index++) { + String id = ProtocolUtils.readString(contents); + String version = ProtocolUtils.readString(contents); + mods.add(new ModInfo.Mod(id, version)); } - return ImmutableList.of(); - } finally { - byteBuf.release(); + return mods.build(); } + + return ImmutableList.of(); } /**