Skip to content

Commit

Permalink
src: fix uninitialized field access in AsyncHooks
Browse files Browse the repository at this point in the history
Co-authored-by: Joyee Cheung <[email protected]>
PR-URL: #48566
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
  • Loading branch information
2 people authored and ruyadorno committed Sep 11, 2023
1 parent dbd6b3c commit 83fe6b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
12 changes: 5 additions & 7 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,13 @@ bool AsyncHooks::pop_async_context(double async_id) {
}

void AsyncHooks::clear_async_id_stack() {
if (env()->can_call_into_js()) {
if (!js_execution_async_resources_.IsEmpty() && env()->can_call_into_js()) {
Isolate* isolate = env()->isolate();
HandleScope handle_scope(isolate);
if (!js_execution_async_resources_.IsEmpty()) {
USE(PersistentToLocal::Strong(js_execution_async_resources_)
->Set(env()->context(),
env()->length_string(),
Integer::NewFromUnsigned(isolate, 0)));
}
USE(PersistentToLocal::Strong(js_execution_async_resources_)
->Set(env()->context(),
env()->length_string(),
Integer::NewFromUnsigned(isolate, 0)));
}

native_execution_async_resources_.clear();
Expand Down
7 changes: 4 additions & 3 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,10 @@ class Environment : public MemoryRetainer {
uv_async_t task_queues_async_;
int64_t task_queues_async_refs_ = 0;

// These may be read by ctors and should be listed before complex fields.
std::atomic_bool is_stopping_{false};
std::atomic_bool can_call_into_js_{true};

AsyncHooks async_hooks_;
ImmediateInfo immediate_info_;
AliasedInt32Array timeout_info_;
Expand Down Expand Up @@ -1034,7 +1038,6 @@ class Environment : public MemoryRetainer {

bool has_serialized_options_ = false;

std::atomic_bool can_call_into_js_ { true };
uint64_t flags_;
uint64_t thread_id_;
std::unordered_set<worker::Worker*> sub_worker_contexts_;
Expand Down Expand Up @@ -1092,8 +1095,6 @@ class Environment : public MemoryRetainer {
CleanupQueue cleanup_queue_;
bool started_cleanup_ = false;

std::atomic_bool is_stopping_ { false };

std::unordered_set<int> unmanaged_fds_;

std::function<void(Environment*, int)> process_exit_handler_ {
Expand Down

0 comments on commit 83fe6b1

Please sign in to comment.