GeezerVison is showing github.com — src: fix uninitialized field access in AsyncHooks · nodejs/node@97bd9cc
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/env.cc +5-7Lines changed: 5 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -170,15 +170,13 @@ bool AsyncHooks::pop_async_context(double async_id) { |
170 | 170 | } |
171 | 171 |
|
172 | 172 | void AsyncHooks::clear_async_id_stack() { |
173 | | - if (env()->can_call_into_js()) { |
| 173 | + if (!js_execution_async_resources_.IsEmpty() && env()->can_call_into_js()) { |
174 | 174 | Isolate* isolate = env()->isolate(); |
175 | 175 | HandleScope handle_scope(isolate); |
176 | | - if (!js_execution_async_resources_.IsEmpty()) { |
177 | | - USE(PersistentToLocal::Strong(js_execution_async_resources_) |
178 | | - ->Set(env()->context(), |
179 | | - env()->length_string(), |
180 | | - Integer::NewFromUnsigned(isolate, 0))); |
181 | | - } |
| 176 | + USE(PersistentToLocal::Strong(js_execution_async_resources_) |
| 177 | + ->Set(env()->context(), |
| 178 | + env()->length_string(), |
| 179 | + Integer::NewFromUnsigned(isolate, 0))); |
182 | 180 | } |
183 | 181 |
|
184 | 182 | native_execution_async_resources_.clear(); |
|
Collapse file
Copy file name to clipboardExpand all lines: src/env.h +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1015,6 +1015,10 @@ class Environment : public MemoryRetainer { |
1015 | 1015 | uv_async_t task_queues_async_; |
1016 | 1016 | int64_t task_queues_async_refs_ = 0; |
1017 | 1017 |
|
| 1018 | + // These may be read by ctors and should be listed before complex fields. |
| 1019 | + std::atomic_bool is_stopping_{false}; |
| 1020 | + std::atomic_bool can_call_into_js_{true}; |
| 1021 | + |
1018 | 1022 | AsyncHooks async_hooks_; |
1019 | 1023 | ImmediateInfo immediate_info_; |
1020 | 1024 | AliasedInt32Array timeout_info_; |
@@ -1092,7 +1096,6 @@ class Environment : public MemoryRetainer { |
1092 | 1096 |
|
1093 | 1097 | bool has_serialized_options_ = false; |
1094 | 1098 |
|
1095 | | - std::atomic_bool can_call_into_js_ { true }; |
1096 | 1099 | uint64_t flags_; |
1097 | 1100 | uint64_t thread_id_; |
1098 | 1101 | std::unordered_set<worker::Worker*> sub_worker_contexts_; |
@@ -1150,8 +1153,6 @@ class Environment : public MemoryRetainer { |
1150 | 1153 | CleanupQueue cleanup_queue_; |
1151 | 1154 | bool started_cleanup_ = false; |
1152 | 1155 |
|
1153 | | - std::atomic_bool is_stopping_ { false }; |
1154 | | - |
1155 | 1156 | std::unordered_set<int> unmanaged_fds_; |
1156 | 1157 |
|
1157 | 1158 | std::function<void(Environment*, ExitCode)> process_exit_handler_{ |
|