mirror of
https://github.com/PaperMC/Waterfall.git
synced 2024-11-06 18:51:21 +01:00
216 lines
9.9 KiB
Diff
216 lines
9.9 KiB
Diff
From 70c35798c174ad82481c381369bb613f26e200e7 Mon Sep 17 00:00:00 2001
|
|
From: LinsaFTW <LinsaFTW@users.noreply.github.com>
|
|
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
|
|
index 3cfef373..5b32cec7 100644
|
|
--- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
|
|
@@ -289,9 +289,15 @@ public class ServerConnector extends PacketHandler
|
|
} 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
|
|
index 474551d3..8716d0c8 100644
|
|
--- 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
|
|
index a3a12e19..214a1fd0 100644
|
|
--- 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
|
|
index 6755fe84..21871d14 100644
|
|
--- 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
|
|
index cefa0206..2cd5740c 100644
|
|
--- 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;
|
|
}
|
|
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java
|
|
index 46e338ca..048ac826 100644
|
|
--- a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java
|
|
@@ -100,23 +100,32 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter
|
|
if ( msg instanceof HAProxyMessage )
|
|
{
|
|
HAProxyMessage proxy = (HAProxyMessage) msg;
|
|
- InetSocketAddress newAddress = new InetSocketAddress( proxy.sourceAddress(), proxy.sourcePort() );
|
|
|
|
- ProxyServer.getInstance().getLogger().log( Level.FINE, "Set remote address via PROXY {0} -> {1}", new Object[]
|
|
+ try
|
|
{
|
|
- channel.getRemoteAddress(), newAddress
|
|
- } );
|
|
+ InetSocketAddress newAddress = new InetSocketAddress( proxy.sourceAddress(), proxy.sourcePort() );
|
|
+
|
|
+ ProxyServer.getInstance().getLogger().log( Level.FINE, "Set remote address via PROXY {0} -> {1}", new Object[]
|
|
+ {
|
|
+ channel.getRemoteAddress(), newAddress
|
|
+ } );
|
|
|
|
- channel.setRemoteAddress( newAddress );
|
|
+ channel.setRemoteAddress( newAddress );
|
|
+ } finally
|
|
+ {
|
|
+ proxy.release();
|
|
+ }
|
|
return;
|
|
}
|
|
|
|
if ( handler != null )
|
|
{
|
|
PacketWrapper packet = (PacketWrapper) msg;
|
|
- boolean sendPacket = handler.shouldHandle( packet );
|
|
+
|
|
try
|
|
{
|
|
+ boolean sendPacket = handler.shouldHandle( packet );
|
|
+
|
|
if ( sendPacket && packet.packet != null )
|
|
{
|
|
try
|
|
--
|
|
2.31.0.windows.1
|
|
|