Repository navigation
BUG: fix leak in reductions when a ufunc override errors or is not found - #31731
Merged
Merged
Conversation
…fail Signed-off-by: Iason Krommydas <[email protected]>
Signed-off-by: Iason Krommydas <[email protected]>
Member
Author
Member
|
Yeah, just out of principle. Seems like a simple test to add and I expect leak sanitizer or so will find it even without a loop. |
Signed-off-by: Iason Krommydas <[email protected]>
Member
Author
Done |
Signed-off-by: Iason Krommydas <[email protected]>
Member
Author
|
The BLAS tests failure should be unrelated |
seberg
approved these changes
Jun 24, 2026
seberg
left a comment
Member
There was a problem hiding this comment.
Thanks, for adding the test, good enough, let's put it in.
| a = A() | ||
| assert_raises(TypeError, np.add.reduce, a) | ||
| assert_raises(TypeError, np.add.accumulate, a) | ||
| assert_raises(TypeError, np.add.reduceat, a, [0]) |
Member
There was a problem hiding this comment.
N.B. I generally prefer with pytest.raises() even if it a lot of old tests use assert_raises.
Member
Author
There was a problem hiding this comment.
Ah thanks. Noted for the future. I intuitively tend to follow existing patterns and I literally just copied it from the tests right above it
charris
pushed a commit
that referenced
this pull request
Jul 3, 2026
…und (#31731) Signed-off-by: Iason Krommydas <[email protected]>
charris
added a commit
that referenced
this pull request
Jul 3, 2026
BUG: fix leak in reductions when a ufunc override errors or is not found (#31731)
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.



PR summary
Closes #31677
Just another thing I noticed while reading reduction code and realised there's an open issue for it already.
One can see this memory leak by doing something like the following and memory profiling that (with memray for example) and will notice the memory is just growing.
I think
goto failis probably nicer thanand I believe it's safe. Only the
else if (override)branch right bellow cannot usegoto failas it needs to return the override and not NULL.I don't think there is a way to have a test regarding the ref count in the python side because
full_argsis created internally in the function in C. But we could have a test that is just the above without the loop and a sanitizer would probably capture the leak. Let me know if you want that. cc @seberg because you wanted a similar test in #31699.First time committer introduction
N/A
AI Disclosure
No AI