GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BUG: Reference leak in PyUFunc_GenericReduction on CheckOverride error · Issue #31677 · numpy/numpy

BUG: Reference leak in PyUFunc_GenericReduction on CheckOverride error #31677

New issue
Copy link
New issue
Copy link
Closed
#31731
Closed
BUG: Reference leak in PyUFunc_GenericReduction on CheckOverride error#31677
#31731
Copy link
Labels
Priority: lowValid, but not for immediate attention

Description

@Fuyugithub
Fuyugithub
opened on Jun 18, 2026
Issue body actions

Bug Description

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

int errval = PyUFunc_CheckOverride(ufunc, _reduce_type[operation],
        full_args.in, full_args.out, wheremask_obj, args, len_args, kwnames, &override);
if (errval) {
    return NULL;    // 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

Activity

  1. seberg
    added
    Priority: lowValid, but not for immediate attention
    on Jun 18, 2026
  2. Vatmuri2 commented on Jun 19, 2026

    @Vatmuri2
    Vatmuri2
    on Jun 19, 2026
    More actions

    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!

  3. jorenham
    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
  4. seberg
    closed this as completedin #31731on Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority: lowValid, but not for immediate attention

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.