diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-01-01 21:42:43 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-01-03 23:44:52 +0100 |
commit | 1f1a373df0121a9e4a2887f69862169b2f4ed2fd (patch) | |
tree | 43ef26e46d83e3bd957e38d45456f51257c11eaf /src/sharedarraybuffer_metadata.cc | |
parent | 7e15f0490a894607ee1cedbe02026793a0f589e5 (diff) | |
download | node-new-1f1a373df0121a9e4a2887f69862169b2f4ed2fd.tar.gz |
worker: use engine-provided deleter for `SharedArrayBuffer`s
Store the full information we have on a given `SharedArrayBuffer`,
and use the deleter provided by the JS engine to free the memory
when that is needed.
This fixes memory lifetime management for WASM buffers that are
passed through a `MessageChannel` (e.g. between threads).
PR-URL: https://github.com/nodejs/node/pull/25307
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Diffstat (limited to 'src/sharedarraybuffer_metadata.cc')
-rw-r--r-- | src/sharedarraybuffer_metadata.cc | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/sharedarraybuffer_metadata.cc b/src/sharedarraybuffer_metadata.cc index 3e760bc50b..671ad6d682 100644 --- a/src/sharedarraybuffer_metadata.cc +++ b/src/sharedarraybuffer_metadata.cc @@ -89,8 +89,7 @@ SharedArrayBufferMetadata::ForSharedArrayBuffer( } SharedArrayBuffer::Contents contents = source->Externalize(); - SharedArrayBufferMetadataReference r(new SharedArrayBufferMetadata( - contents.Data(), contents.ByteLength())); + SharedArrayBufferMetadataReference r(new SharedArrayBufferMetadata(contents)); if (r->AssignToSharedArrayBuffer(env, context, source).IsNothing()) return nullptr; return r; @@ -111,17 +110,22 @@ Maybe<bool> SharedArrayBufferMetadata::AssignToSharedArrayBuffer( obj); } -SharedArrayBufferMetadata::SharedArrayBufferMetadata(void* data, size_t size) - : data(data), size(size) { } +SharedArrayBufferMetadata::SharedArrayBufferMetadata( + const SharedArrayBuffer::Contents& contents) + : contents_(contents) { } SharedArrayBufferMetadata::~SharedArrayBufferMetadata() { - free(data); + contents_.Deleter()(contents_.Data(), + contents_.ByteLength(), + contents_.DeleterData()); } MaybeLocal<SharedArrayBuffer> SharedArrayBufferMetadata::GetSharedArrayBuffer( Environment* env, Local<Context> context) { Local<SharedArrayBuffer> obj = - SharedArrayBuffer::New(env->isolate(), data, size); + SharedArrayBuffer::New(env->isolate(), + contents_.Data(), + contents_.ByteLength()); if (AssignToSharedArrayBuffer(env, context, obj).IsNothing()) return MaybeLocal<SharedArrayBuffer>(); |