Repository navigation
Fix reference leak in is_namedtuple_class when _fields is not a tuple - #1377
Merged
Siyet merged 1 commit intoNov 28, 2026
Merged
Conversation
…uple `is_namedtuple_class` returned early without releasing the `_fields` reference when it was not exactly a `tuple`, so every decoder built for such a `tuple` subclass leaked one reference.
shashank11yadav
force-pushed
the
fix/is-namedtuple-fields-leak
branch
from
November 28, 2026 02:11
c49f8bb to
26c5e6a
Compare
Contributor
|
Thx for the fix. |
Siyet
added a commit
that referenced
this pull request
Nov 28, 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.
Fixes #1376
When a
tuplesubclass has a_fieldsattribute that is not exactly atuple(for example a list),is_namedtuple_classreturned early without releasing the reference it got fromPyObject_GetAttr. Each decoder built for such a class leaked one reference to_fields.The fix adds the missing
Py_DECREF(fields)before that early return insrc/msgspec/_core.c.NamedTupleInfo_Convertalready releases its reference on every path and is unchanged.Testing:
test_namedtuple_like_fields_not_tuple_no_leakintests/unit/test_json.py. Without the fix it fails (reference count of_fieldsis 14, expected 4, after 10 decoder builds). With the fix it passes.Changelog entry added under
Unreleased.