From 9475a966ca732deb58b2d141bfc65390419dcaa9 Mon Sep 17 00:00:00 2001 From: syeyoung Date: Sat, 19 Nov 2022 21:19:20 +0900 Subject: - Prevent Reference Leak via ProtectionDomain - Prevent Reference Leak via ThreadDownloadImageData (set imagebuffer to null) Signed-off-by: syeyoung --- .../dungeonsguide/launcher/loader/DGClassLoader.java | 3 ++- .../java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java | 13 +++++++++++++ .../syeyoung/dungeonsguide/mod/discord/gamesdk/GameSDK.java | 1 - 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/DGClassLoader.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/DGClassLoader.java index 4a902d8d..b7ead0f0 100644 --- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/DGClassLoader.java +++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/loader/DGClassLoader.java @@ -1,5 +1,6 @@ package kr.syeyoung.dungeonsguide.launcher.loader; +import kr.syeyoung.dungeonsguide.launcher.Main; import kr.syeyoung.dungeonsguide.launcher.events.DGAwareEventSubscriptionTransformer; import net.minecraft.launchwrapper.LaunchClassLoader; import net.minecraftforge.fml.relauncher.ReflectionHelper; @@ -77,7 +78,7 @@ public abstract class DGClassLoader extends ClassLoader implements ByteStreamURL } if (res != null) { res = eventSubscriptionTransformer.transform(name, name, res); - return defineClass(name, res, 0, res.length); + return defineClass(name, res, 0, res.length, Main.class.getProtectionDomain()); } else { throw new ClassNotFoundException(name); } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java index f3c600fc..5ef83afa 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java @@ -51,7 +51,10 @@ import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.*; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.client.network.NetworkPlayerInfo; +import net.minecraft.client.renderer.ThreadDownloadImageData; import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.texture.ITextureObject; +import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.resources.IResourceManager; import net.minecraft.client.resources.IResourcePack; import net.minecraft.command.CommandHandler; @@ -60,6 +63,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.launchwrapper.LaunchClassLoader; import net.minecraft.network.play.server.S38PacketPlayerListItem; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.client.event.GuiOpenEvent; @@ -333,6 +337,15 @@ public class DungeonsGuide implements DGInterface { } } + Map mapTextureObjects = ReflectionHelper.getPrivateValue(TextureManager.class, Minecraft.getMinecraft().getTextureManager(), "mapTextureObjects", "field_110585_a", "b"); + for (ITextureObject value : mapTextureObjects.values()) { + if (value instanceof ThreadDownloadImageData) { + ReflectionHelper.setPrivateValue(ThreadDownloadImageData.class,(ThreadDownloadImageData) value, null, "imageBuffer", "field_110563_c", "k"); + } + } + + + World world = Minecraft.getMinecraft().getRenderManager().worldObj; if (world != null) { for (AbstractClientPlayer entity : world.getEntities(AbstractClientPlayer.class, input -> true)) { diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/gamesdk/GameSDK.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/gamesdk/GameSDK.java index cde3f7e2..c6fecb33 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/gamesdk/GameSDK.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/discord/gamesdk/GameSDK.java @@ -76,7 +76,6 @@ public class GameSDK { public static void cleanup() { // com.sun.jna.CallbackReference has reference of DiscordCallback. idk how i should approach fixing this -> I would better write native lib myself later. if (System.getProperty("dg.safe") == null) return; - Map infos = ReflectionHelper.getPrivateValue(Structure.class, null, "layoutInfo"); infos.clear(); Map options = ReflectionHelper.getPrivateValue(Native.class, null, "options"); -- cgit