diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-08-18 01:05:48 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-08-20 01:14:10 +0300 |
commit | 119c4ccf0ef2addc84fd638004a631f55c7aefc9 (patch) | |
tree | 03e2889956067200c5d84285a16288707a415ab3 /src/node_worker.cc | |
parent | bdf07f4317ce738bbe56c5b91aaebf35d15052a8 (diff) |
worker: fix crash when SharedArrayBuffer outlives creating thread
Keep a reference to the `ArrayBuffer::Allocator` alive for at least
as long as a `SharedArrayBuffer` allocated by it lives.
Refs: https://github.com/nodejs/node/pull/28788
Fixes: https://github.com/nodejs/node/issues/28777
Fixes: https://github.com/nodejs/node/issues/28773
PR-URL: https://github.com/nodejs/node/pull/29190
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src/node_worker.cc')
-rw-r--r-- | src/node_worker.cc | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/node_worker.cc b/src/node_worker.cc index 8f97f5c3514..11e44a92757 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -59,6 +59,7 @@ Worker::Worker(Environment* env, per_isolate_opts_(per_isolate_opts), exec_argv_(exec_argv), platform_(env->isolate_data()->platform()), + array_buffer_allocator_(ArrayBufferAllocator::Create()), start_profiler_idle_notifier_(env->profiler_idle_notifier_started()), thread_id_(Environment::AllocateThreadId()), env_vars_(env->env_vars()) { @@ -102,17 +103,20 @@ bool Worker::is_stopped() const { return stopped_; } +std::shared_ptr<ArrayBufferAllocator> Worker::array_buffer_allocator() { + return array_buffer_allocator_; +} + // This class contains data that is only relevant to the child thread itself, // and only while it is running. // (Eventually, the Environment instance should probably also be moved here.) class WorkerThreadData { public: explicit WorkerThreadData(Worker* w) - : w_(w), - array_buffer_allocator_(ArrayBufferAllocator::Create()) { + : w_(w) { CHECK_EQ(uv_loop_init(&loop_), 0); - Isolate* isolate = NewIsolate(array_buffer_allocator_.get(), &loop_); + Isolate* isolate = NewIsolate(w->array_buffer_allocator_.get(), &loop_); CHECK_NOT_NULL(isolate); { @@ -124,7 +128,7 @@ class WorkerThreadData { isolate_data_.reset(CreateIsolateData(isolate, &loop_, w_->platform_, - array_buffer_allocator_.get())); + w->array_buffer_allocator_.get())); CHECK(isolate_data_); if (w_->per_isolate_opts_) isolate_data_->set_options(std::move(w_->per_isolate_opts_)); @@ -166,7 +170,6 @@ class WorkerThreadData { private: Worker* const w_; uv_loop_t loop_; - std::unique_ptr<ArrayBufferAllocator> array_buffer_allocator_; DeleteFnPtr<IsolateData, FreeIsolateData> isolate_data_; friend class Worker; |