Waterfall/Waterfall-Proxy-Patches/0025-Fix-ByteBuf-memory-leaks.patch

173 lines
8.2 KiB
Diff
Raw Normal View History

2021-05-01 18:41:28 +02:00
From 72f7c8263253c704f24a8cc7634a9760b7aa9717 Mon Sep 17 00:00:00 2001
2021-05-01 00:32:57 +02:00
From: linsaftw <linsaftw@users.noreply.github.com>
2021-03-20 17:31:50 +01:00
Date: Sat, 20 Mar 2021 12:36:25 -0300
Subject: [PATCH] Fix ByteBuf memory leaks
diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
2021-05-01 18:41:28 +02:00
index 522bd93d..494375cd 100644
2021-03-20 17:31:50 +01:00
--- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
+++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
2021-05-01 15:58:52 +02:00
@@ -284,9 +284,15 @@ public class ServerConnector extends PacketHandler
2021-03-20 17:31:50 +01:00
} else
{
ByteBuf brand = ByteBufAllocator.DEFAULT.heapBuffer();
- DefinedPacket.writeString(brandString, brand);
- user.unsafe().sendPacket( new PluginMessage( user.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand", brand, handshakeHandler.isServerForge() ) );
- brand.release();
+
+ try
+ {
+ DefinedPacket.writeString(brandString, brand);
+ user.unsafe().sendPacket( new PluginMessage( user.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand", brand, handshakeHandler.isServerForge() ) );
+ } finally
+ {
+ brand.release();
+ }
}
// Travertine end
}
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
2021-05-01 18:41:28 +02:00
index 474551d3..8716d0c8 100644
2021-03-20 17:31:50 +01:00
--- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
+++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
@@ -294,12 +294,21 @@ public class DownstreamBridge extends PacketHandler
try
{
ByteBuf brand = Unpooled.wrappedBuffer(pluginMessage.getData());
- String serverBrand = DefinedPacket.readString(brand);
- brand.release();
- brand = ByteBufAllocator.DEFAULT.heapBuffer();
- DefinedPacket.writeString(bungee.getName() + " <- " + serverBrand, brand ); // Waterfall
- pluginMessage.setData(brand);
- brand.release();
+ String serverBrand = null;
+
+ try {
+ serverBrand = DefinedPacket.readString(brand);
+ } finally {
+ brand.release();
+ }
+
+ try {
+ brand = ByteBufAllocator.DEFAULT.heapBuffer();
+ DefinedPacket.writeString(bungee.getName() + " <- " + serverBrand, brand ); // Waterfall
+ pluginMessage.setData(brand);
+ } finally {
+ brand.release();
+ }
} catch (Exception ProtocolHacksSuck)
{
return;
diff --git a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java
2021-05-01 18:41:28 +02:00
index a3a12e19..214a1fd0 100644
2021-03-20 17:31:50 +01:00
--- a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java
+++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java
@@ -143,11 +143,17 @@ public abstract class EntityMap
if ( readId == oldId || readId == newId )
{
ByteBuf data = packet.copy();
- packet.readerIndex( offset );
- packet.writerIndex( offset );
- DefinedPacket.writeVarInt( readId == oldId ? newId : oldId, packet );
- packet.writeBytes( data );
- data.release();
+
+ try
+ {
+ packet.readerIndex( offset );
+ packet.writerIndex( offset );
+ DefinedPacket.writeVarInt( readId == oldId ? newId : oldId, packet );
+ packet.writeBytes( data );
+ } finally
+ {
+ data.release();
+ }
}
}
diff --git a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_7_6.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_7_6.java
2021-05-01 18:41:28 +02:00
index 6755fe84..21871d14 100644
2021-03-20 17:31:50 +01:00
--- a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_7_6.java
+++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_7_6.java
@@ -39,19 +39,27 @@ class EntityMap_1_7_6 extends EntityMap_1_7_2
&& profile.getProperties().length >= 1 )
{
ByteBuf rest = packet.copy();
- packet.readerIndex( readerIndex );
- packet.writerIndex( readerIndex + packetIdLength + idLength );
- DefinedPacket.writeString( player.getUniqueId().toString(), packet );
- DefinedPacket.writeString( username, packet );
- DefinedPacket.writeVarInt( profile.getProperties().length, packet );
- for ( LoginResult.Property property : profile.getProperties() )
+
+ try
+ {
+ packet.readerIndex( readerIndex );
+ packet.writerIndex( readerIndex + packetIdLength + idLength );
+ DefinedPacket.writeString( player.getUniqueId().toString(), packet );
+ DefinedPacket.writeString( username, packet );
+ DefinedPacket.writeVarInt( profile.getProperties().length, packet );
+
+ for ( LoginResult.Property property : profile.getProperties() )
+ {
+ DefinedPacket.writeString( property.getName(), packet );
+ DefinedPacket.writeString( property.getValue(), packet );
+ DefinedPacket.writeString( property.getSignature(), packet );
+ }
+
+ packet.writeBytes( rest );
+ } finally
{
- DefinedPacket.writeString( property.getName(), packet );
- DefinedPacket.writeString( property.getValue(), packet );
- DefinedPacket.writeString( property.getSignature(), packet );
+ rest.release();
}
- packet.writeBytes( rest );
- rest.release();
}
}
}
diff --git a/proxy/src/main/java/net/md_5/bungee/forge/ForgeUtils.java b/proxy/src/main/java/net/md_5/bungee/forge/ForgeUtils.java
2021-05-01 18:41:28 +02:00
index cefa0206..2cd5740c 100644
2021-03-20 17:31:50 +01:00
--- a/proxy/src/main/java/net/md_5/bungee/forge/ForgeUtils.java
+++ b/proxy/src/main/java/net/md_5/bungee/forge/ForgeUtils.java
@@ -38,15 +38,27 @@ public class ForgeUtils
{
Map<String, String> modTags = new HashMap<>();
ByteBuf payload = Unpooled.wrappedBuffer( pluginMessage.getData() );
- byte discriminator = payload.readByte();
- if ( discriminator == 2 ) // ModList
+
+ try
{
- ByteBuf buffer = payload.slice();
- int modCount = DefinedPacket.readVarInt( buffer, 2 );
- for ( int i = 0; i < modCount; i++ )
+ byte discriminator = payload.readByte();
+ if ( discriminator == 2 ) // ModList
{
- modTags.put( DefinedPacket.readString( buffer ), DefinedPacket.readString( buffer ) );
+ ByteBuf buffer = payload.slice();
+
+ try {
+ int modCount = DefinedPacket.readVarInt( buffer, 2 );
+ for ( int i = 0; i < modCount; i++ )
+ {
+ modTags.put( DefinedPacket.readString( buffer ), DefinedPacket.readString( buffer ) );
+ }
+ } finally
+ {
+ buffer.release();
+ }
}
+ } finally {
+ payload.release();
}
return modTags;
}
2021-05-01 04:48:48 +02:00
--
2.31.1
2021-03-20 17:31:50 +01:00