Repository navigation
BUG: release the input of casts to object when move_references is set (#33278) - #33294
Merged
Merged
Conversation
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.
Backport of #33278.
PR summary
A ufunc that writes
StringDTyperesults into an object array leaks memory once the array is larger than the iterator buffer (8192 elements). For example:LeakSanitizer reports on
main:The cast to object is supposed to clear its input when it is asked to move references, which is how these buffers get released.
_strided_to_strided_any_to_objectcalled the clear function with its loop counter after the loop had counted it down to zero, so nothing was cleared. The same bug leaks references when the buffer is a structured dtype with object fields.Pass the original element count to the clear function, and also clear the input when converting an element fails partway through.
The existing tests write buffers that hold references back into numeric and structured arrays, but never into an object array, so nothing covered this cast. I extended
test_iter_buffered_cast_structured_typewith a refcount check that fails onmain, andtest_nditer_distinct_allocatorswith aStringDTypebuffer written back to an object array.