diff --git a/src/tracing/node_trace_buffer.cc b/src/tracing/node_trace_buffer.cc index 3b7119f6d57f68..796c9f529288e5 100644 --- a/src/tracing/node_trace_buffer.cc +++ b/src/tracing/node_trace_buffer.cc @@ -1,4 +1,5 @@ #include "tracing/node_trace_buffer.h" +#include "util-inl.h" namespace node { namespace tracing { @@ -170,15 +171,25 @@ void NodeTraceBuffer::NonBlockingFlushSignalCb(uv_async_t* signal) { // static void NodeTraceBuffer::ExitSignalCb(uv_async_t* signal) { - NodeTraceBuffer* buffer = reinterpret_cast(signal->data); - uv_close(reinterpret_cast(&buffer->flush_signal_), nullptr); - uv_close(reinterpret_cast(&buffer->exit_signal_), + NodeTraceBuffer* buffer = + ContainerOf(&NodeTraceBuffer::exit_signal_, signal); + + // Close both flush_signal_ and exit_signal_. + uv_close(reinterpret_cast(&buffer->flush_signal_), [](uv_handle_t* signal) { + NodeTraceBuffer* buffer = + ContainerOf(&NodeTraceBuffer::flush_signal_, + reinterpret_cast(signal)); + + uv_close(reinterpret_cast(&buffer->exit_signal_), + [](uv_handle_t* signal) { NodeTraceBuffer* buffer = - reinterpret_cast(signal->data); - Mutex::ScopedLock scoped_lock(buffer->exit_mutex_); - buffer->exited_ = true; - buffer->exit_cond_.Signal(scoped_lock); + ContainerOf(&NodeTraceBuffer::exit_signal_, + reinterpret_cast(signal)); + Mutex::ScopedLock scoped_lock(buffer->exit_mutex_); + buffer->exited_ = true; + buffer->exit_cond_.Signal(scoped_lock); + }); }); }