From 30c80cbe6f1ed890baa44e9eb60a1c09e069ca80 Mon Sep 17 00:00:00 2001 From: Jason Ginchereau Date: Wed, 4 Jan 2017 15:21:26 -0800 Subject: [PATCH] src: fix TracingController cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes an incorrect deletion of the `TracingController` instance, which in some environments could cause an error about an invalid pointer passed to `free()`. The `TracingController` instance is actually owned by a `unique_ptr` member of the platform, so calling `platform::SetTracingController(nullptr)` is the correct way to delete it. But before that, the `TraceBuffer` must be deleted in order for the tracing loop to exit; that is accomplished by calling `TracingController::Initialize(nullptr)`. PR-URL: https://github.com/nodejs/node/pull/10623 Reviewed-By: Matthew Loring Reviewed-By: Michaƫl Zasso --- src/tracing/agent.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tracing/agent.cc b/src/tracing/agent.cc index 97a3e11a2c458c..ceab09e5a2789c 100644 --- a/src/tracing/agent.cc +++ b/src/tracing/agent.cc @@ -56,7 +56,9 @@ void Agent::Stop() { // Perform final Flush on TraceBuffer. We don't want the tracing controller // to flush the buffer again on destruction of the V8::Platform. tracing_controller_->StopTracing(); - delete tracing_controller_; + tracing_controller_->Initialize(nullptr); + tracing_controller_ = nullptr; + // Thread should finish when the tracing loop is stopped. uv_thread_join(&thread_); v8::platform::SetTracingController(platform_, nullptr);