Skip to content

Commit

Permalink
async_wrap: close the destroy_ids_idle_handle_
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
reshnm authored and MylesBorins committed May 18, 2017
1 parent 0c318a6 commit 62a8f47
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@ inline void Environment::CleanupHandles() {
delete hc;
}

// 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);
}
Expand Down

0 comments on commit 62a8f47

Please sign in to comment.