From 455f7260d0b54b3cae7d8b6971a6bfac80867282 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 2 Sep 2026 22:27:44 +0000 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 --- 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 929998a7f239..4e26befd7471 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;