summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2020-05-23 07:44:10 -0600
committerGitHub <noreply@github.com>2020-05-23 07:44:10 -0600
commitba5205c1b8a7bebdf37535c701ffcd8bd79362bb (patch)
tree7d0a016f98942836686c209bb65106b7b0b5e68e /numpy
parenta699f2879ab3836fe6d1619c518c85956a3075c1 (diff)
parent1e7ef595cf6ec20c321a93387916f05309f3b4fa (diff)
downloadnumpy-ba5205c1b8a7bebdf37535c701ffcd8bd79362bb.tar.gz
Merge pull request #16348 from seberg/fromany-leak
BUG: Fix dtype leak in `PyArray_FromAny` error path
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/ctors.c2
-rw-r--r--numpy/lib/tests/test_function_base.py9
2 files changed, 11 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index 502ab0ea9..9e8646b25 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -2029,12 +2029,14 @@ PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,
PyErr_SetString(PyExc_ValueError,
"object of too small depth for desired array");
Py_DECREF(arr);
+ Py_XDECREF(newtype);
ret = NULL;
}
else if (max_depth != 0 && PyArray_NDIM(arr) > max_depth) {
PyErr_SetString(PyExc_ValueError,
"object too deep for desired array");
Py_DECREF(arr);
+ Py_XDECREF(newtype);
ret = NULL;
}
else {
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index 008ea0759..9ba0be56a 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -2423,6 +2423,15 @@ class TestBincount:
assert_equal(sys.getrefcount(np.dtype(np.intp)), intp_refcount)
assert_equal(sys.getrefcount(np.dtype(np.double)), double_refcount)
+ @pytest.mark.parametrize("vals", [[[2, 2]], 2])
+ def test_error_not_1d(self, vals):
+ # Test that values has to be 1-D (both as array and nested list)
+ vals_arr = np.asarray(vals)
+ with assert_raises(ValueError):
+ np.bincount(vals_arr)
+ with assert_raises(ValueError):
+ np.bincount(vals)
+
class TestInterp: