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: typecode reference leak in array_setstate on 4 error paths (methods.c) · Issue #31678 · numpy/numpy

BUG: typecode reference leak in array_setstate on 4 error paths (methods.c) #31678

New issue
Copy link
New issue
Copy link
Closed
Closed
BUG: typecode reference leak in array_setstate on 4 error paths (methods.c)#31678
Copy link

Description

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

Bug Description

In numpy/_core/src/multiarray/methods.c, after Py_INCREF(typecode) at line 2100, four early return NULL paths skip the matching Py_DECREF(typecode), leaking the reference.

Location

numpy/_core/src/multiarray/methods.c:2100-2131

Code

Py_INCREF(typecode);        // line 2100: refcount incremented

if (nd < 0) {
    return NULL;            // line 2103: typecode LEAKED
}
// ...
if (dimensions[i] < 0) {
    return NULL;            // line 2118: typecode LEAKED
}
// ...
if (overflow) {
    PyErr_NoMemory();
    return NULL;            // line 2123: typecode LEAKED
}
// ...
if (!PyList_Check(rawdata)) {
    return NULL;            // line 2131: typecode LEAKED
}

Impact

Every failed ndarray unpickling operation leaks the typecode reference. This affects pickle.loads() / numpy.loads() on corrupted or malformed ndarray pickle data.

Suggested Fix

Replace all early return NULL with goto fail where fail does Py_DECREF(typecode):

fail:
    Py_DECREF(typecode);
    return NULL;

Environment

  • NumPy version: current main
  • Affected: ndarray.__setstate__() (unpickling)

Activity

  1. jorenham
    changed the title [-][BUG] typecode reference leak in array_setstate on 4 error paths (methods.c)[/-] [+]BUG: typecode reference leak in array_setstate on 4 error paths (methods.c)[/+] on Jun 22, 2026
  2. ngoldbaum commented on Jun 23, 2026

    @ngoldbaum
    ngoldbaum
    on Jun 23, 2026
    Member
    More actions

    Fixed by #31701

  3. ngoldbaum
    closed this as completedon Jun 23, 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

    No labels
    No labels

    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.