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: typecode reference leak in array_setstate on 4 error paths (methods.c) #31678
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 incrementedif (nd<0) {
returnNULL; // line 2103: typecode LEAKED
}
// ...if (dimensions[i] <0) {
returnNULL; // line 2118: typecode LEAKED
}
// ...if (overflow) {
PyErr_NoMemory();
returnNULL; // line 2123: typecode LEAKED
}
// ...if (!PyList_Check(rawdata)) {
returnNULL; // 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):
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
Activity
[-][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)[/+]ngoldbaum commentedon Jun 23, 2026
Fixed by #31701