src: stop leaking a CppHeap in CommonEnvironmentSetup - #65792
Open
codebytere wants to merge 1 commit into
Open
Conversation
`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: nodejs#55337 Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
Collaborator
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65792 +/- ##
==========================================
+ Coverage 89.99% 90.15% +0.15%
==========================================
Files 757 769 +12
Lines 257739 261448 +3709
Branches 48881 49661 +780
==========================================
+ Hits 231961 235715 +3754
+ Misses 16861 16749 -112
- Partials 8917 8984 +67
🚀 New features to boost your workflow:
|
jasnell
approved these changes
Sep 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CommonEnvironmentSetup's constructor created av8::CppHeapfor itsIsolate::CreateParamsup front, but on the non-snapshotting path it then callsNewIsolate(), which ignoresparams->cpp_heapand attaches either the heap fromIsolateSettingsor a fresh one. The heap created first was never attached to an isolate and never destroyed, so everyCommonEnvironmentSetup::Create()/CreateFromSnapshot()leaked oneCppHeap. cppgc's process-wide heap registry keeps a pointer to it, which is why LeakSanitizer does not report it; countingCppHeapconstructions against destructions over two setups shows 4 against 2 before this change and 2 against 2 after.The heap is now only created on the snapshotting path, where the params are handed to the
SnapshotCreatorand the heap does get attached.Tests: existing
test/embeddingsuite; no new test, since there is no public API to enumerate detached CppHeaps.Refs: #55337
Disclosure: the code and this description were written by Claude Code, directed and reviewed by @codebytere.