src: free placeholder nodes for cppgc wrappers in MemoryTracker - #65793
Open
codebytere wants to merge 1 commit into
Open
src: free placeholder nodes for cppgc wrappers in MemoryTracker#65793codebytere wants to merge 1 commit into
codebytere wants to merge 1 commit into
Conversation
`MemoryTracker::AddNode(const CppgcMixin*)` allocates a `MemoryRetainerNode` that only stands in for the wrapper's JS node while its `MemoryInfo()` runs; unlike the other node kinds it is not handed to the `EmbedderGraph`, and nothing freed it. Every heap snapshot (or other `BuildEmbedderGraph` call) leaked one node per live `vm.Script` or `vm` context. Keep the placeholders in the tracker and free them with it, and make the already-seen path in `Track(const CppgcMixin*)` add its edge to the wrapper's JS node like the first visit does, so the graph never refers to a placeholder. Refs: nodejs#56534 Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
Collaborator
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65793 +/- ##
==========================================
+ Coverage 89.99% 90.14% +0.14%
==========================================
Files 757 769 +12
Lines 257739 261450 +3711
Branches 48881 49644 +763
==========================================
+ Hits 231961 235685 +3724
+ Misses 16861 16786 -75
- Partials 8917 8979 +62
🚀 New features to boost your workflow:
|
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.
MemoryTracker::AddNode(const CppgcMixin*)allocates aMemoryRetainerNodethat only stands in for the wrapper's JS node on the tracker's stack whileMemoryInfo()runs (the comment inTrack()calls it a dummy). The otherAddNode()overloads hand their node to thev8::EmbedderGraph, which owns it; this one does not, and nothing else freed it. Every heap snapshot,--heapsnapshot-near-heap-limittrigger or inspectorHeapProfiler.takeHeapSnapshotleaked 56 bytes per livevm.Script/vmcontext:node -e "globalThis.s = new vm.Script('1'); v8.getHeapSnapshot()"under LSAN shows it.The tracker now owns these placeholders and frees them when it is destroyed; its constructor and destructor move to
memory_tracker-inl.hbecause the member needs the completeMemoryRetainerNodetype. The already-seen branch ofTrack(const CppgcMixin*)adds its edge to the wrapper's JS node like the first visit does, so nothing in the graph ever points at a placeholder.Tests:
EnvironmentTest.HeapSnapshotWithCppgcWrappersDoesNotLeaktakes a heap snapshot from C++ with avm.Scriptand a context alive; LeakSanitizer reports the nodes before and is clean after (it asserts nothing without LSAN).test-heapsnapshot*,test-v8-*heap*,test-heapdump*andpummel/test-heapdump-vm-scriptpass.Refs: #56534
Disclosure: the code, test and this description were written by Claude Code, directed and reviewed by @codebytere.