mirror of
https://github.com/napi-rs/napi-rs.git
synced 2025-12-08 19:56:07 +00:00
* fix(napi): fix memory leak in Promise::from_unknown() This commit fixes a memory leak that occurred when converting a Promise from an Unknown object, specifically manifesting in Deno environments. The issue was in the `promise_callback_finalizer` function, which had a type mismatch when cleaning up callback allocations: 1. The callback was stored as `Box<(Cb, *mut bool)>` (a tuple containing the callback and an executed flag pointer) 2. The finalizer incorrectly cast it as `Box<Cb>` when trying to free it 3. This caused improper deallocation and memory leaks The fix ensures: - The executed flag allocation is always properly cleaned up - The callback tuple is cast to the correct type `(Cb, *mut bool)` before being dropped - All allocations are properly freed in both execution paths (callback executed or not executed) Fixes #2926 --------- Co-authored-by: Claude <noreply@anthropic.com>