Skip to content

Commit

Permalink
BUG: Decrement ref count in gentype_reduce when allocated memory not …
Browse files Browse the repository at this point in the history
…used
  • Loading branch information
aayushagrawal135 committed Nov 8, 2022
1 parent 9a6d956 commit 89b5038
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions numpy/core/src/multiarray/scalartypes.c.src
Original file line number Diff line number Diff line change
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 89b5038

Please sign in to comment.