From b57f715649134f52423f6b2f703210d23ee02de0 Mon Sep 17 00:00:00 2001 From: Aikar Date: Fri, 8 May 2020 20:40:42 -0400 Subject: [PATCH] Fix CraftServer.unloadWorld Leak The dimension manager was still registered which leaked the entire World --- .../Fix-CraftServer.unloadWorld-Leak.patch | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 Spigot-Server-Patches/Fix-CraftServer.unloadWorld-Leak.patch diff --git a/Spigot-Server-Patches/Fix-CraftServer.unloadWorld-Leak.patch b/Spigot-Server-Patches/Fix-CraftServer.unloadWorld-Leak.patch new file mode 100644 index 0000000000..cb097bf3ee --- /dev/null +++ b/Spigot-Server-Patches/Fix-CraftServer.unloadWorld-Leak.patch @@ -0,0 +1,123 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Aikar +Date: Fri, 8 May 2020 20:30:58 -0400 +Subject: [PATCH] Fix CraftServer.unloadWorld Leak + +The dimension manager was still registered which leaked the entire World + +diff --git a/src/main/java/net/minecraft/server/DimensionManager.java b/src/main/java/net/minecraft/server/DimensionManager.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/DimensionManager.java ++++ b/src/main/java/net/minecraft/server/DimensionManager.java +@@ -0,0 +0,0 @@ public class DimensionManager implements MinecraftSerializable { + private final boolean hasSkyLight; + private final GenLayerZoomer genLayerZoomer; + ++ // Paper start ++ public static void unregister(String s, DimensionManager dimensionmanager) { ++ MinecraftServer.getServer().execute(() -> { ++ RegistryMaterials registry = (RegistryMaterials) IRegistry.DIMENSION_TYPE; ++ registry.deleteValue(new MinecraftKey(s), dimensionmanager); ++ }); ++ } ++ // Paper end + public static DimensionManager register(String s, DimensionManager dimensionmanager) { + return (DimensionManager) IRegistry.a(IRegistry.DIMENSION_TYPE, dimensionmanager.id, s, dimensionmanager); + } +diff --git a/src/main/java/net/minecraft/server/RegistryID.java b/src/main/java/net/minecraft/server/RegistryID.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/RegistryID.java ++++ b/src/main/java/net/minecraft/server/RegistryID.java +@@ -0,0 +0,0 @@ import javax.annotation.Nullable; + public class RegistryID implements Registry { + + private static final Object a = null; +- private K[] b; ++ private K[] b; // Paper - diff below + private int[] c; +- private K[] d; ++ private K[] d; // Paper - diff below + private int e; + private int f; + private java.util.BitSet usedIds; // Paper ++ // Paper start ++ public void removeValue(K value) { ++ removeValue(value, this.b); ++ removeValue(value, this.d); ++ rehash(this.b.length); ++ } ++ public void removeValue(K value, K[] arr) { ++ for (int i = 0; i < arr.length; i++) { ++ K k = arr[i]; ++ if (k == value) { ++ arr[i] = null; ++ } ++ } ++ } + + public RegistryID(int i) { + i = (int) ((float) i / 0.8F); +@@ -0,0 +0,0 @@ public class RegistryID implements Registry { + return this.e; + } + ++ private void rehash(int i) { d(i); } // Paper - OBFHELPER + private void d(int i) { + K[] ak = this.b; + int[] aint = this.c; +diff --git a/src/main/java/net/minecraft/server/RegistryMaterials.java b/src/main/java/net/minecraft/server/RegistryMaterials.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/RegistryMaterials.java ++++ b/src/main/java/net/minecraft/server/RegistryMaterials.java +@@ -0,0 +0,0 @@ public class RegistryMaterials extends IRegistryWritable { + private int V; + + public RegistryMaterials() {} ++ public T deleteValue(MinecraftKey minecraftkey, T value) { ++ this.b.removeValue(value); // Diff 1 ++ this.d = null; // Diff 2 ++ return this.c.remove(minecraftkey); // Diff 3 ++ } + + @Override + public V a(int i, MinecraftKey minecraftkey, V v0) { +- this.b.a(v0, i); ++ this.b.a(v0, i); // Paper - diff above 1 + Validate.notNull(minecraftkey); + Validate.notNull(v0); +- this.d = null; ++ this.d = null; // Diff 2 + if (this.c.containsKey(minecraftkey)) { + RegistryMaterials.LOGGER.debug("Adding duplicate key '{}' to registry", minecraftkey); + } + +- this.c.put(minecraftkey, v0); ++ this.c.put(minecraftkey, v0); // Paper - diff3 + if (this.V <= i) { + this.V = i + 1; + } +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +@@ -0,0 +0,0 @@ import net.minecraft.server.EntityPlayer; + import net.minecraft.server.EnumDifficulty; + import net.minecraft.server.EnumGamemode; + import net.minecraft.server.IRecipe; ++import net.minecraft.server.IRegistry; + import net.minecraft.server.Item; + import net.minecraft.server.ItemWorldMap; + import net.minecraft.server.Items; +@@ -0,0 +0,0 @@ public final class CraftServer implements Server { + } + + worlds.remove(world.getName().toLowerCase(java.util.Locale.ENGLISH)); +- console.worldServer.remove(handle.getWorldProvider().getDimensionManager()); ++ // Paper start ++ DimensionManager dimensionManager = handle.getWorldProvider().getDimensionManager(); ++ DimensionManager.unregister(world.getName(), dimensionManager); ++ console.worldServer.remove(dimensionManager); ++ // Paper end + return true; + } +