Repository navigation
Add IMallocSpy interface - Prepare for better memory leak detection. - #997
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #997 +/- ##
==========================================
+ Coverage 91.71% 91.84% +0.12%
==========================================
Files 150 150
Lines 15424 15668 +244
==========================================
+ Hits 14146 14390 +244
Misses 1278 1278 ☔ View full report in Codecov by Harness. 🚀 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.
Related to #971
Summary
Add the
IMallocSpyCOM interface and its registration functions (CoRegisterMallocSpy,CoRevokeMallocSpy) tomalloc.py. Add full test coverage intest/test_malloc.py.Why
The previous two PRs (#995 and #996) improved
find_memleak.But
find_memleakstill has a limit: it only sees the total memory of the process.It cannot tell which allocation leaked.
If a test fails, we know memory grew, but we do not know where the leak is.
IMallocSpysolves this. It is a standard COM interface.When you register a spy, COM calls your hook functions before and after every memory operation (
Alloc,Free,Realloc,GetSize,DidAlloc,HeapMinimize).The spy sees every single allocation and free, with the exact size and pointer.
By adding
IMallocSpynow, we prepare the codebase for the next step: a per-allocation leak detector. This future tool will:Freeto itsAllocThis is a small, safe change. It only adds the interface definition and registration. It does not change any existing behavior.
The tests prove the hooks fire in the correct order and with the correct arguments.
Why this is the right preparation
IMallocSpyis a documented Microsoft interface. No custom hacks.Out of Scope
IMallocSpyactive by default.find_memleakto use the spy (that comes later).Trade-offs
Pros:
Cons:
Justification
This is a preparatory refactor.
The motivation is clear: the previous PRs made leak detection stronger at the process level.
The natural next step is allocation-level detection.
IMallocSpyis the Windows-provided tool for that.Adding it now, with full tests, makes the next step easy and safe.