Skip to content

src: stop leaking a CppHeap in CommonEnvironmentSetup - #65792

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
codebytere:fix/embedder-setup-cppheap-leak
Sep 7, 2026
Merged

src: stop leaking a CppHeap in CommonEnvironmentSetup#65792
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
codebytere:fix/embedder-setup-cppheap-leak

Conversation

@codebytere

@codebytere codebytere commented Sep 4, 2026

Copy link
Copy Markdown
Member

Every CommonEnvironmentSetup::Create() and CreateFromSnapshot() leaks one v8::CppHeap: the constructor created a heap for its CreateParams up front, but the non-snapshotting path then calls NewIsolate(), which ignores params->cpp_heap and attaches its own, so the first heap was never attached or destroyed (LSAN stays quiet because cppgc's heap registry still points at it).

The heap is now created only on the snapshotting path, where the params go to the SnapshotCreator and V8 takes ownership.

Tests: test/embedding passes; no new test, since detached CppHeaps cannot be enumerated.

Refs: #55337


Disclosure: the code and this description were written by Claude Code, directed and reviewed by @codebytere.

`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>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Sep 4, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.15%. Comparing base (2befec5) to head (455f726).
⚠️ Report is 119 commits behind head on main.

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     
Files with missing lines Coverage Δ
src/api/embed_helpers.cc 75.00% <100.00%> (ø)

... and 101 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@panva panva added author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue PRs queued for automated landing through the Commit Queue. labels Sep 7, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 8e4d830 into nodejs:main Sep 7, 2026
83 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 8e4d830

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants