Skip to content

Commit

Permalink
Merge pull request #22597 from charris/backport-22557
Browse files Browse the repository at this point in the history
BUG: Decrement ref count in gentype_reduce if allocated memory not used
  • Loading branch information
charris committed Nov 15, 2022
2 parents 0d3d500 + dcd4847 commit bb5e3a6
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions numpy/core/src/multiarray/scalartypes.c.src
Expand Up @@ -1753,11 +1753,13 @@ gentype_reduce(PyObject *self, PyObject *NPY_UNUSED(args))

mod = PyImport_ImportModule("numpy.core._multiarray_umath");
if (mod == NULL) {
Py_DECREF(ret);
return NULL;
}
obj = PyObject_GetAttrString(mod, "scalar");
Py_DECREF(mod);
if (obj == NULL) {
Py_DECREF(ret);
return NULL;
}
PyTuple_SET_ITEM(ret, 0, obj);
Expand All @@ -1766,6 +1768,7 @@ gentype_reduce(PyObject *self, PyObject *NPY_UNUSED(args))
PyObject *val = PyArrayScalar_VAL(self, Object);
PyObject *tup = Py_BuildValue("NO", obj, val);
if (tup == NULL) {
Py_DECREF(ret);
return NULL;
}
PyTuple_SET_ITEM(ret, 1, tup);
Expand All @@ -1774,11 +1777,13 @@ gentype_reduce(PyObject *self, PyObject *NPY_UNUSED(args))
/* a structured dtype with an object in a field */
PyArrayObject *arr = (PyArrayObject *)PyArray_FromScalar(self, NULL);
if (arr == NULL) {
Py_DECREF(ret);
return NULL;
}
/* Use the whole array which handles sturctured void correctly */
PyObject *tup = Py_BuildValue("NN", obj, arr);
if (tup == NULL) {
Py_DECREF(ret);
return NULL;
}
PyTuple_SET_ITEM(ret, 1, tup);
Expand Down

0 comments on commit bb5e3a6

Please sign in to comment.