From 7331f5cfcc8b69669f3c2494ffd3435f7ce7ba7b 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 c1bcb3948c4..051110c9c6e 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(); impl_->snapshot_creator.emplace(isolate, params); isolate->SetCaptureStackTraceForUncaughtExceptions(