diff options
author | mattip <matti.picus@gmail.com> | 2018-09-25 22:47:25 +0300 |
---|---|---|
committer | mattip <matti.picus@gmail.com> | 2018-09-26 20:24:09 +0300 |
commit | df68e6485e8a9cedb784293ca5d704aba0cf3dbc (patch) | |
tree | bac6eafd305d85a383d312af0307769347bba323 | |
parent | e9d3e2045af728504d4a8ea16fbf2fb2d0a47bbf (diff) | |
download | numpy-df68e6485e8a9cedb784293ca5d704aba0cf3dbc.tar.gz |
BUG: reused otmp caused refcount problem
-rw-r--r-- | numpy/core/src/multiarray/convert_datatype.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/numpy/core/src/multiarray/convert_datatype.c b/numpy/core/src/multiarray/convert_datatype.c index 83343b861..33a706412 100644 --- a/numpy/core/src/multiarray/convert_datatype.c +++ b/numpy/core/src/multiarray/convert_datatype.c @@ -2028,7 +2028,6 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn) { int i, n, allscalars = 0; PyArrayObject **mps = NULL; - PyObject *otmp = NULL; PyArray_Descr *intype = NULL, *stype = NULL; PyArray_Descr *newtype = NULL; NPY_SCALARKIND scalarkind = NPY_NOSCALAR, intypekind = NPY_NOSCALAR; @@ -2067,9 +2066,13 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn) } for (i = 0; i < n; i++) { - otmp = PySequence_GetItem(op, i); + PyObject *otmp = PySequence_GetItem(op, i); + if (otmp == NULL) { + goto fail; + } if (!PyArray_CheckAnyScalar(otmp)) { newtype = PyArray_DescrFromObject(otmp, intype); + Py_DECREF(otmp); Py_XDECREF(intype); if (newtype == NULL) { goto fail; @@ -2079,6 +2082,7 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn) } else { newtype = PyArray_DescrFromObject(otmp, stype); + Py_DECREF(otmp); Py_XDECREF(stype); if (newtype == NULL) { goto fail; @@ -2088,7 +2092,6 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn) mps[i] = (PyArrayObject *)Py_None; Py_INCREF(Py_None); } - Py_XDECREF(otmp); } if (intype == NULL) { /* all scalars */ @@ -2126,8 +2129,9 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn) /* Make sure all arrays are actual array objects. */ for (i = 0; i < n; i++) { int flags = NPY_ARRAY_CARRAY; + PyObject *otmp = PySequence_GetItem(op, i); - if ((otmp = PySequence_GetItem(op, i)) == NULL) { + if (otmp == NULL) { goto fail; } if (!allscalars && ((PyObject *)(mps[i]) == Py_None)) { @@ -2136,8 +2140,8 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn) Py_DECREF(Py_None); } Py_INCREF(intype); - mps[i] = (PyArrayObject*) - PyArray_FromAny(otmp, intype, 0, 0, flags, NULL); + mps[i] = (PyArrayObject*)PyArray_FromAny(otmp, intype, 0, 0, + flags, NULL); Py_DECREF(otmp); if (mps[i] == NULL) { goto fail; @@ -2150,7 +2154,6 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn) fail: Py_XDECREF(intype); Py_XDECREF(stype); - Py_XDECREF(otmp); *retn = 0; for (i = 0; i < n; i++) { Py_XDECREF(mps[i]); |