summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Feng <rainwoodman@gmail.com>2016-10-19 12:03:30 -0700
committerYu Feng <rainwoodman@gmail.com>2016-10-20 11:24:39 -0700
commit42829407289f85a9151de033bf77ba92ad865c1a (patch)
tree47413541cd5378c9f0b25046f99c34709f072bc3
parent6da5f00fff528354d3676617b91b024007e62ecd (diff)
downloadpython-numpy-42829407289f85a9151de033bf77ba92ad865c1a.tar.gz
python-numpy-42829407289f85a9151de033bf77ba92ad865c1a.tar.bz2
python-numpy-42829407289f85a9151de033bf77ba92ad865c1a.zip
BUG: protect stolen ref by NewFromDescr in array_empty
fixes #8179
-rw-r--r--numpy/core/src/multiarray/ctors.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index b2ef0c451..d32b1c937 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -2895,20 +2895,27 @@ PyArray_Empty(int nd, npy_intp *dims, PyArray_Descr *type, int is_f_order)
PyArrayObject *ret;
if (!type) type = PyArray_DescrFromType(NPY_DEFAULT_TYPE);
+
+ /*
+ * PyArray_NewFromDescr steals a ref,
+ * but we need to look at type later.
+ * */
+ Py_INCREF(type);
+
ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type,
type, nd, dims,
NULL, NULL,
is_f_order, NULL);
- if (ret == NULL) {
- return NULL;
- }
- if (PyDataType_REFCHK(type)) {
+ if (ret != NULL && PyDataType_REFCHK(type)) {
PyArray_FillObjectArray(ret, Py_None);
if (PyErr_Occurred()) {
Py_DECREF(ret);
+ Py_DECREF(type);
return NULL;
}
}
+
+ Py_DECREF(type);
return (PyObject *)ret;
}