You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Python] ConvertToSequenceAndInferSize leaks a reference to a list and the items when iterator raises an Exception #50591
I started investigating and I found that we could leak a reference and the items contained on the list when converting an iterator that raises an Exception at ConvertToSequenceAndInferSize.
I created a test that currently fails:
deftest_failing_iterator_does_not_leak():
# ConvertToSequenceAndInferSize builds an intermediate list. If the# iterator raises, that list and everything already stored in it leaks.importgc# Create an arbitrary long int that is probably not cached by the interpretervalue=10**20defraising_iter():
for_inrange(5):
yieldvalueraiseValueError("boom")
gc.collect()
original_refcount=sys.getrefcount(value)
withpytest.raises(ValueError, match="boom"):
pa.array(raising_iter(), size=100)
gc.collect()
assertsys.getrefcount(value) ==original_refcount
The issue is in RETURN_IF_PYERROR(); error case where lst is not Py_DECREF:
changed the title [-][Python] ConvertToSequenceAndInferSize leaks a reference when iterator raises an Exception[/-][+][Python] ConvertToSequenceAndInferSize leaks a reference to a list and the items when iterator raises an Exception[/+]on Jul 22, 2026
Activity
[-][Python] ConvertToSequenceAndInferSize leaks a reference when iterator raises an Exception[/-][+][Python] ConvertToSequenceAndInferSize leaks a reference to a list and the items when iterator raises an Exception[/+]GH-50591: [Python] Fix reference in ConvertToSequenceAndInferSize whe…
raulcd commentedon Jul 22, 2026
Issue resolved by pull request 50594
#50594