Fix reference leak when decoding msgpack Ext payloads - #1109
Merged
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
This was referenced Jul 3, 2026
pull Bot
pushed a commit
to Future-Outlier/msgspec
that referenced
this pull request
Jul 3, 2026
Batches the changelog entries accumulated since the 0.21.1 release, following the usual pre-release batching practice (like msgspec#1020). Covers merged user-facing changes through msgspec#1109/msgspec#978/msgspec#1105; internal CI/benchmarking/test-infra changes are intentionally omitted. Also records the move to the msgspec GitHub organization. --------- Co-authored-by: Siyet <[email protected]>
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.
Fixes #1108.
Ext_Newdoesn't steal the reference todata(it does its ownPy_INCREF, matching the borrow contract expected by theExtconstructor). Both decode branches inmpack_decode_ext(typedExtdecode, andAnydecode without anext_hook) passed a fresh reference fromPyBytes_FromStringAndSizeand never released it, leaking one bytes object (the ext payload) per decoded Ext. Thedatetime(code -1) andext_hookbranches were not affected.The fix releases the caller's reference after constructing the
Ext, same pattern as theRaw.copy()leak fix (#709). Verified empirically: RSS delta over 200k decodes of a 1 KiB payload went from ~205 MiB to 0 on both affected branches; the new test fails before the fix (sys.getrefcount3 vs 2) and passes after.Thanks @K-ANOY for the precise report, the ownership analysis there was spot on.