summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2017-02-06 11:59:37 -0700
committerGitHub <noreply@github.com>2017-02-06 11:59:37 -0700
commit98b3127fa61e09387e1f7cf925acfcb36043e48a (patch)
tree96317ca406edcd58905ac8366a4ca92cd88efb7c /numpy
parentca248b72589c39e3138e8bd7b658c1bd5dca209a (diff)
parentf17010be098b26154b86b19442691a5e7542ea6f (diff)
downloadnumpy-98b3127fa61e09387e1f7cf925acfcb36043e48a.tar.gz
Merge pull request #8571 from juliantaylor/dbg-fixes
BUG: fix calling python api with error set and minor leaks
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/descriptor.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/numpy/core/src/multiarray/descriptor.c b/numpy/core/src/multiarray/descriptor.c
index 613c4ca1c..6c2186f9c 100644
--- a/numpy/core/src/multiarray/descriptor.c
+++ b/numpy/core/src/multiarray/descriptor.c
@@ -1041,8 +1041,11 @@ _convert_from_dict(PyObject *obj, int align)
}
n = PyObject_Length(names);
offsets = Borrowed_PyMapping_GetItemString(obj, "offsets");
+ if (!offsets) {
+ PyErr_Clear();
+ }
titles = Borrowed_PyMapping_GetItemString(obj, "titles");
- if (!offsets || !titles) {
+ if (!titles) {
PyErr_Clear();
}
@@ -1097,6 +1100,8 @@ _convert_from_dict(PyObject *obj, int align)
tup = PyTuple_New(len);
descr = PyObject_GetItem(descrs, ind);
if (!descr) {
+ Py_DECREF(tup);
+ Py_DECREF(ind);
goto fail;
}
if (align) {
@@ -1120,17 +1125,23 @@ _convert_from_dict(PyObject *obj, int align)
long offset;
off = PyObject_GetItem(offsets, ind);
if (!off) {
+ Py_DECREF(tup);
+ Py_DECREF(ind);
goto fail;
}
offset = PyArray_PyIntAsInt(off);
if (offset == -1 && PyErr_Occurred()) {
Py_DECREF(off);
+ Py_DECREF(tup);
+ Py_DECREF(ind);
goto fail;
}
Py_DECREF(off);
if (offset < 0) {
PyErr_Format(PyExc_ValueError, "offset %d cannot be negative",
(int)offset);
+ Py_DECREF(tup);
+ Py_DECREF(ind);
goto fail;
}
@@ -1159,14 +1170,20 @@ _convert_from_dict(PyObject *obj, int align)
PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));
totalsize += newdescr->elsize;
}
+ if (ret == NPY_FAIL) {
+ Py_DECREF(ind);
+ Py_DECREF(tup);
+ goto fail;
+ }
if (len == 3) {
PyTuple_SET_ITEM(tup, 2, title);
}
name = PyObject_GetItem(names, ind);
+ Py_DECREF(ind);
if (!name) {
+ Py_DECREF(tup);
goto fail;
}
- Py_DECREF(ind);
#if defined(NPY_PY3K)
if (!PyUString_Check(name)) {
#else
@@ -1174,14 +1191,16 @@ _convert_from_dict(PyObject *obj, int align)
#endif
PyErr_SetString(PyExc_ValueError,
"field names must be strings");
- ret = NPY_FAIL;
+ Py_DECREF(tup);
+ goto fail;
}
/* Insert into dictionary */
if (PyDict_GetItem(fields, name) != NULL) {
PyErr_SetString(PyExc_ValueError,
"name already used as a name or title");
- ret = NPY_FAIL;
+ Py_DECREF(tup);
+ goto fail;
}
PyDict_SetItem(fields, name, tup);
Py_DECREF(name);
@@ -1194,7 +1213,8 @@ _convert_from_dict(PyObject *obj, int align)
if (PyDict_GetItem(fields, title) != NULL) {
PyErr_SetString(PyExc_ValueError,
"title already used as a name or title.");
- ret=NPY_FAIL;
+ Py_DECREF(tup);
+ goto fail;
}
PyDict_SetItem(fields, title, tup);
}