From 4058d532f243b773573ea42b648b925625a1cb76 Mon Sep 17 00:00:00 2001 From: Jichan Date: Wed, 8 Jan 2020 21:36:05 +0900 Subject: [PATCH] src: fix what a dispose without checking If created platform with CreatePlatform, the crash occurs because it does not check if it was initialized to v8_platform when DisposePlatform was called. --- src/node_v8_platform-inl.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/node_v8_platform-inl.h b/src/node_v8_platform-inl.h index ecd8f21d1a2653..711d6fba064793 100644 --- a/src/node_v8_platform-inl.h +++ b/src/node_v8_platform-inl.h @@ -12,6 +12,7 @@ #include "tracing/node_trace_writer.h" #include "tracing/trace_event.h" #include "tracing/traced_value.h" +#include "util.h" namespace node { @@ -79,8 +80,15 @@ class NodeTraceStateObserver }; struct V8Platform { + bool initialize_; + + V8Platform() + : initialize_(false) {} + #if NODE_USE_V8_PLATFORM inline void Initialize(int thread_pool_size) { + CHECK(!initialize_); + initialize_ = true; tracing_agent_ = std::make_unique(); node::tracing::TraceEventHelper::SetAgent(tracing_agent_.get()); node::tracing::TracingController* controller = @@ -99,6 +107,10 @@ struct V8Platform { } inline void Dispose() { + if(!initialize_) + return; + initialize_ = false; + StopTracingAgent(); platform_->Shutdown(); delete platform_;