Skip to content

Commit 62a8f47

Browse files
reshnmMylesBorins
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 0c318a6 commit 62a8f47

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/env-inl.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,16 @@ inline void Environment::CleanupHandles() {
271271
delete hc;
272272
}
273273

274+
// Closing the destroy_ids_idle_handle_ within the handle cleanup queue
275+
// prevents the async wrap destroy hook from being called.
276+
uv_handle_t* handle =
277+
reinterpret_cast<uv_handle_t*>(&destroy_ids_idle_handle_);
278+
handle->data = this;
279+
handle_cleanup_waiting_ = 1;
280+
uv_close(handle, [](uv_handle_t* handle) {
281+
static_cast<Environment*>(handle->data)->FinishHandleCleanup(handle);
282+
});
283+
274284
while (handle_cleanup_waiting_ != 0)
275285
uv_run(event_loop(), UV_RUN_ONCE);
276286
}

0 commit comments

Comments
 (0)