Skip to content

Commit

Permalink
src: fix what a dispose without checking
Browse files Browse the repository at this point in the history
If created platform with CreatePlatform, the crash occurs because
it does not check if it was initialized to v8_platform
when DisposePlatform was called.

Backport-PR-URL: #35241
Refs: #31260
Co-authored-by: Anna Henningsen <[email protected]>
PR-URL: #30467
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
  • Loading branch information
Jichan and addaleax committed Sep 23, 2020
1 parent 2f8f767 commit a28c990
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/node_v8_platform-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -79,8 +80,12 @@ class NodeTraceStateObserver
};

struct V8Platform {
bool initialized_ = false;

#if NODE_USE_V8_PLATFORM
inline void Initialize(int thread_pool_size) {
CHECK(!initialized_);
initialized_ = true;
tracing_agent_ = std::make_unique<tracing::Agent>();
node::tracing::TraceEventHelper::SetAgent(tracing_agent_.get());
node::tracing::TracingController* controller =
Expand All @@ -99,6 +104,10 @@ struct V8Platform {
}

inline void Dispose() {
if (!initialized_)
return;
initialized_ = false;

StopTracingAgent();
platform_->Shutdown();
delete platform_;
Expand Down

0 comments on commit a28c990

Please sign in to comment.