diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/buffer.c | 10 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 9 |
2 files changed, 17 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/buffer.c b/numpy/core/src/multiarray/buffer.c index 5b8156ff2..763874bc7 100644 --- a/numpy/core/src/multiarray/buffer.c +++ b/numpy/core/src/multiarray/buffer.c @@ -740,16 +740,22 @@ _descriptor_from_pep3118_format(char *s) } *p = '\0'; + str = PyUString_FromStringAndSize(buf, strlen(buf)); + free(buf); + if (str == NULL) { + return NULL; + } + /* Convert */ _numpy_internal = PyImport_ImportModule("numpy.core._internal"); if (_numpy_internal == NULL) { + Py_DECREF(str); return NULL; } - str = PyUString_FromStringAndSize(buf, strlen(buf)); - free(buf); descr = (PyArray_Descr*)PyObject_CallMethod( _numpy_internal, "_dtype_from_pep3118", "O", str); Py_DECREF(str); + Py_DECREF(_numpy_internal); if (descr == NULL) { PyErr_Format(PyExc_ValueError, "'%s' is not a valid PEP 3118 buffer format string", buf); diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 460261694..b3a4337ca 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -1728,5 +1728,14 @@ if sys.version_info >= (2, 6): x = np.array([(1,),(2,)], dtype={'f0': (int, j)}) self._check_roundtrip(x) + def test_reference_leak(self): + count_1 = sys.getrefcount(np.core._internal) + a = np.zeros(4) + b = memoryview(a) + c = np.asarray(b) + count_2 = sys.getrefcount(np.core._internal) + assert_equal(count_1, count_2) + + if __name__ == "__main__": run_module_suite() |