diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2022-11-15 14:44:25 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-15 14:44:25 -0600 |
commit | bb5e3a671f1fab8bf39346c760cf65009f91bea2 (patch) | |
tree | 01afded572a5d45d6a9c623939162b35a387b4cb | |
parent | 0d3d50045fdb4012e51d47ab95e9fbbbbd08ca00 (diff) | |
parent | dcd4847b8d855ff3568ebf86792bd10e4873d803 (diff) | |
download | numpy-bb5e3a671f1fab8bf39346c760cf65009f91bea2.tar.gz |
Merge pull request #22597 from charris/backport-22557
BUG: Decrement ref count in gentype_reduce if allocated memory not used
-rw-r--r-- | numpy/core/src/multiarray/scalartypes.c.src | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src index e1f236001..9764fb2a1 100644 --- a/numpy/core/src/multiarray/scalartypes.c.src +++ b/numpy/core/src/multiarray/scalartypes.c.src @@ -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); @@ -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); @@ -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); |