summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2017-02-02 22:17:11 +0100
committerJulian Taylor <jtaylor.debian@googlemail.com>2017-02-06 11:42:31 +0100
commitf17010be098b26154b86b19442691a5e7542ea6f (patch)
tree1db27f979475c5b894f5ec9f7649f0dc64090af6
parent9ae84854d9c48a751e57c5cd0e9636678a6d2359 (diff)
downloadnumpy-f17010be098b26154b86b19442691a5e7542ea6f.tar.gz
BUG: fix calling python api with error set and minor leaks
-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 c966440ac..325d4b2ce 100644
--- a/numpy/core/src/multiarray/descriptor.c
+++ b/numpy/core/src/multiarray/descriptor.c
@@ -990,8 +990,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();
}
@@ -1046,6 +1049,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) {
@@ -1069,17 +1074,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;
}
@@ -1108,14 +1119,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
@@ -1123,14 +1140,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);
@@ -1143,7 +1162,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);
}