From d9cd99cda9ac98acb19fd6f2109eb38e0f72de38 Mon Sep 17 00:00:00 2001 From: RacoonDog <32882447+RacoonDog@users.noreply.github.com> Date: Fri, 10 Nov 2023 09:43:55 -0500 Subject: [PATCH] Fix PlayerHeadTexture memory leaks (#4196) --- .../meteorclient/utils/render/PlayerHeadTexture.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/utils/render/PlayerHeadTexture.java b/src/main/java/meteordevelopment/meteorclient/utils/render/PlayerHeadTexture.java index 94c0b47524..34a451889d 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/render/PlayerHeadTexture.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/render/PlayerHeadTexture.java @@ -8,10 +8,12 @@ import org.lwjgl.BufferUtils; import org.lwjgl.stb.STBImage; import org.lwjgl.system.MemoryStack; +import org.lwjgl.system.MemoryUtil; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.IOException; +import java.io.InputStream; import java.nio.ByteBuffer; import java.nio.IntBuffer; @@ -65,8 +67,8 @@ public PlayerHeadTexture(String url) { } public PlayerHeadTexture() { - try { - ByteBuffer data = TextureUtil.readResource(mc.getResourceManager().getResource(new MeteorIdentifier("textures/steve.png")).get().getInputStream()); + try (InputStream inputStream = mc.getResourceManager().getResource(new MeteorIdentifier("textures/steve.png")).get().getInputStream()) { + ByteBuffer data = TextureUtil.readResource(inputStream); data.rewind(); try (MemoryStack stack = MemoryStack.stackPush()) { @@ -78,6 +80,7 @@ public PlayerHeadTexture() { upload(image); STBImage.stbi_image_free(image); } + MemoryUtil.memFree(data); } catch (IOException e) { e.printStackTrace();