Files
bun.sh/test/napi
Claude Bot 66a84b353d fix(napi): tie external buffer finalizer to ArrayBuffer lifecycle
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>
2026-01-24 20:34:16 +00:00
..