LongYinan 52c0da5c19
fix(napi): memory leak in PromiseRaw cleanup callback (#2995)
* 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>
2025-11-06 17:07:00 +08:00
..
2025-10-24 09:47:01 +08:00
2025-10-24 09:47:01 +08:00