From 8e4d830a1bb5d0e6621bd672e2a684e2b1c901fc Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 7 Sep 2026 14:34:37 +0200 Subject: [PATCH] src: stop leaking a CppHeap in CommonEnvironmentSetup `CommonEnvironmentSetup` created a `CppHeap` for its `CreateParams` before deciding how to create the isolate, but `NewIsolate()` ignores `params->cpp_heap` and attaches a heap of its own (or the one from `IsolateSettings`). The first heap was never attached or destroyed, so every non-snapshotting setup leaked one `CppHeap`; cppgc's heap registry keeps it reachable, which is why LSAN stays quiet about it. Only create the heap on the snapshotting path, where the params go to the `SnapshotCreator` directly. Refs: https://github.com/nodejs/node/pull/55337 Signed-off-by: Shelley Vohr PR-URL: https://github.com/nodejs/node/pull/65792 Reviewed-By: James M Snell Reviewed-By: Joyee Cheung Reviewed-By: Jake Yuesong Li --- src/api/embed_helpers.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/embed_helpers.cc b/src/api/embed_helpers.cc index 929998a7f23..4e26befd747 100644 --- a/src/api/embed_helpers.cc +++ b/src/api/embed_helpers.cc @@ -117,8 +117,6 @@ CommonEnvironmentSetup::CommonEnvironmentSetup( Isolate::CreateParams params; params.array_buffer_allocator = impl_->allocator.get(); params.external_references = external_references.data(); - params.cpp_heap = - v8::CppHeap::Create(platform, v8::CppHeapCreateParams{{}}).release(); Isolate* isolate; @@ -130,6 +128,8 @@ CommonEnvironmentSetup::CommonEnvironmentSetup( // isolate, so that the memory reducer can be initialized. isolate = impl_->isolate = Isolate::Allocate(GetOrCreateIsolateGroup()); platform->RegisterIsolate(isolate, loop); + params.cpp_heap = + v8::CppHeap::Create(platform, v8::CppHeapCreateParams{{}}).release(); if (snapshot_config != nullptr && snapshot_config->base_blob != nullptr) { params.snapshot_blob = snapshot_config->base_blob;