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 <shelley.vohr@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65792
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
This commit is contained in:
Shelley Vohr authored and Antoine du Hamel committed 2026-09-22 16:55:40 +02:00
1 parent aed73444de
commit 7331f5cfcc
1 file changed
+2 -2
+2 -2
View File
@@ -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(