Skip to content

Commit 94c4323

Browse files
reshnmitaloacasas
authored andcommitted
async_wrap: close the destroy_ids_idle_handle_
The destroy_ids_idle_handle_ needs to be closed on environment destruction. Not closing the handle leaves a dangling pointer in the used uv loop. This leads to undefined behavior when the uv loop is used after the environment has been destroyed. PR-URL: #10385 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 1253650 commit 94c4323

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/env-inl.h

+13
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,19 @@ inline Environment::~Environment() {
207207
delete hc;
208208
}
209209

210+
while (handle_cleanup_waiting_ != 0)
211+
uv_run(event_loop(), UV_RUN_ONCE);
212+
213+
// Closing the destroy_ids_idle_handle_ within the handle cleanup queue
214+
// prevents the async wrap destroy hook from being called.
215+
uv_handle_t* handle =
216+
reinterpret_cast<uv_handle_t*>(&destroy_ids_idle_handle_);
217+
handle->data = this;
218+
handle_cleanup_waiting_ = 1;
219+
uv_close(handle, [](uv_handle_t* handle) {
220+
static_cast<Environment*>(handle->data)->FinishHandleCleanup(handle);
221+
});
222+
210223
while (handle_cleanup_waiting_ != 0)
211224
uv_run(event_loop(), UV_RUN_ONCE);
212225

0 commit comments

Comments
 (0)