0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

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: https://github.com/nodejs/node/pull/10385
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
René Schünemann 2016-12-21 11:36:50 +01:00 committed by James M Snell
parent c00f647963
commit c7ff96b0f7

View File

@ -207,6 +207,19 @@ inline Environment::~Environment() {
delete hc;
}
while (handle_cleanup_waiting_ != 0)
uv_run(event_loop(), UV_RUN_ONCE);
// Closing the destroy_ids_idle_handle_ within the handle cleanup queue
// prevents the async wrap destroy hook from being called.
uv_handle_t* handle =
reinterpret_cast<uv_handle_t*>(&destroy_ids_idle_handle_);
handle->data = this;
handle_cleanup_waiting_ = 1;
uv_close(handle, [](uv_handle_t* handle) {
static_cast<Environment*>(handle->data)->FinishHandleCleanup(handle);
});
while (handle_cleanup_waiting_ != 0)
uv_run(event_loop(), UV_RUN_ONCE);