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: DType reference leak in _convert_from_type (descriptor.c) #31676
In numpy/_core/src/multiarray/descriptor.c, PyArray_DiscoverDTypeFromScalarType returns a new reference, but PyArray_GetDefaultDescr does NOT steal it. The DType reference is leaked unconditionally.
PyArray_GetDefaultDescr returns a new reference (via Py_INCREF or NPY_DT_CALL_default_descr). It does NOT steal the DType reference. Therefore DType is leaked on every successful call to _convert_from_type with a scalar type. This triggers on every custom scalar type → dtype conversion.
Suggested Fix
PyObject*DType=PyArray_DiscoverDTypeFromScalarType(typ);
if (DType!=NULL) {
PyArray_Descr*ret=PyArray_GetDefaultDescr((PyArray_DTypeMeta*)DType);
Py_DECREF(DType);
returnret;
}
Environment
NumPy version: current main
Affected: numpy.dtype() conversions from custom scalar types
All of these seem like real but very minor issues (besides one theoretically they they have zero real world impact).
But as a note, fully automated results should try to be brief and more importantly make a note of that.
changed the title [-][BUG] DType reference leak in _convert_from_type (descriptor.c)[/-][+]BUG: DType reference leak in _convert_from_type (descriptor.c)[/+]on Jun 22, 2026
Activity
seberg commentedon Jun 18, 2026
All of these seem like real but very minor issues (besides one theoretically they they have zero real world impact).
But as a note, fully automated results should try to be brief and more importantly make a note of that.
[-][BUG] DType reference leak in _convert_from_type (descriptor.c)[/-][+]BUG: DType reference leak in _convert_from_type (descriptor.c)[/+]