mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 03:18:53 +00:00
Previously, `napi_create_external_buffer` used a two-stage finalization approach: it created the ArrayBuffer with an empty finalizer, then added the real finalizer separately via `vm.heap.addFinalizer()`. This caused a race condition where native code could free/reuse the underlying memory while Bun still held a reference to the ArrayBuffer. The fix passes the finalizer directly to `ArrayBuffer::createFromBytes`, matching the approach already used by `napi_create_external_arraybuffer`. This ties the cleanup correctly to the ArrayBuffer's lifecycle. Fixes #26423 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>