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
BUG: Reference leak in PyUFunc_GenericReduction on CheckOverride error #31677
In numpy/_core/src/umath/ufunc_object.c, when PyUFunc_CheckOverride fails in PyUFunc_GenericReduction, the code returns NULL directly instead of jumping to the cleanup label, leaking full_args.in and full_args.out.
Location
numpy/_core/src/umath/ufunc_object.c:3777-3780
Code
interrval=PyUFunc_CheckOverride(ufunc, _reduce_type[operation],
full_args.in, full_args.out, wheremask_obj, args, len_args, kwnames, &override);
if (errval) {
returnNULL; // BUG: should be `goto fail` — leaks full_args.in/out
}
Impact
When reduce/accumulate/reduceat encounters a __array_ufunc__ override error, the full_args.in and full_args.out tuple references are leaked. This happens every time an override is attempted on an object that raises an exception in its __array_ufunc__ implementation.
Suggested Fix
if (errval) {
goto fail; // cleanup path that DECREFs full_args
}
Environment
NumPy version: current main
Affected: np.add.reduce(), np.accumulate() etc. with __array_ufunc__ overrides that raise
Saw this is marked low priority. I was looking for a good first contribution and I'd love to take this one if it's still up for grabs!
My plan: the one-line goto fail fix, plus a regression test that checks the operand's refcount stays flat when array_ufunc raises during a reduce. I'll get a PR up soon. Totally happy to adjust the plan, would love to learn from this, let me know if there's any other considerations!
changed the title [-][BUG] Reference leak in PyUFunc_GenericReduction on CheckOverride error[/-][+]BUG: Reference leak in PyUFunc_GenericReduction on CheckOverride error[/+]on Jun 22, 2026
Activity
Vatmuri2 commentedon Jun 19, 2026
Saw this is marked low priority. I was looking for a good first contribution and I'd love to take this one if it's still up for grabs!
My plan: the one-line goto fail fix, plus a regression test that checks the operand's refcount stays flat when array_ufunc raises during a reduce. I'll get a PR up soon. Totally happy to adjust the plan, would love to learn from this, let me know if there's any other considerations!
[-][BUG] Reference leak in PyUFunc_GenericReduction on CheckOverride error[/-][+]BUG: Reference leak in PyUFunc_GenericReduction on CheckOverride error[/+]