From 98ef5e767e2e77b02cbfb056a12a7cb88f3f96d5 Mon Sep 17 00:00:00 2001 From: kb1000 Date: Fri, 29 Sep 2023 07:23:12 +0200 Subject: [PATCH] fix(core) callback wrapper memory leak When using the CHM closure registry, the Java-side wrapper object was never removed from the map. --- doc/notes/3.3.4.md | 1 + .../lwjgl/core/src/main/java/org/lwjgl/system/Callback.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/notes/3.3.4.md b/doc/notes/3.3.4.md index 10742822a3..1a98802e49 100644 --- a/doc/notes/3.3.4.md +++ b/doc/notes/3.3.4.md @@ -10,6 +10,7 @@ This build includes the following changes: #### Fixes +- Core: Fixed callback wrapper memory leak with the CHM closure registry. (#927) - tinyfd: The `aDefaultPath` parameter of `tinyfd_selectFolderDialog` is now nullable. (#922) #### Breaking Changes diff --git a/modules/lwjgl/core/src/main/java/org/lwjgl/system/Callback.java b/modules/lwjgl/core/src/main/java/org/lwjgl/system/Callback.java index 8e7a2cf053..1d96d142ab 100644 --- a/modules/lwjgl/core/src/main/java/org/lwjgl/system/Callback.java +++ b/modules/lwjgl/core/src/main/java/org/lwjgl/system/Callback.java @@ -206,7 +206,7 @@ public static void free(long functionPointer) { MemoryManage.DebugAllocator.untrack(functionPointer); } - FFIClosure closure = CLOSURE_REGISTRY.get(functionPointer); + FFIClosure closure = CLOSURE_REGISTRY.remove(functionPointer); DeleteGlobalRef(closure.user_data()); ffi_closure_free(closure); @@ -234,4 +234,4 @@ public String toString() { return String.format("%s pointer [0x%X]", getClass().getSimpleName(), address); } -} \ No newline at end of file +}