Skip to content

BUG: Fix reference leakage for output arrays in reduction functions #29414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2025

Conversation

charris
Copy link
Member

@charris charris commented Jul 22, 2025

Backport of #29358.

Fixes #29355.

We already increment a reference to out in _set_out_array (in ufunc_object.c):

c
static int
_set_out_array(PyObject *obj, PyArrayObject **store)
{
    ...
    Py_INCREF(obj);
    *store = (PyArrayObject *)obj;

    return 0;
    ...
}

This PR removes additional increments and adds a missing decrement that caused the memory leakage.

…umpy#29358)

Add back missing DECREF for `out=` in ufunc.reduce (and etc.) when `out` is passed.

* BUG: add Py_XDECREF to `out` for failure case in generic reduction

* TST: add reference count checks for `out` in reduction leak tests
@charris charris added this to the 2.3.2 release milestone Jul 22, 2025
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs labels Jul 22, 2025
@charris charris changed the base branch from main to maintenance/2.3.x July 22, 2025 15:31
@charris charris changed the title Backport 29358 BUG: Fix reference leakage for output arrays in reduction functions Jul 22, 2025
@charris charris merged commit db022e2 into numpy:maintenance/2.3.x Jul 22, 2025
10 checks passed
@charris charris deleted the backport-29358 branch July 22, 2025 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 08 - Backport Used to tag backport PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Memory leak using out= parameter in numpy version 2.3
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy