summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/src/multiarray/item_selection.c1
-rw-r--r--numpy/core/tests/test_multiarray.py7
2 files changed, 8 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c
index 8c80c26f1..3b66ad66a 100644
--- a/numpy/core/src/multiarray/item_selection.c
+++ b/numpy/core/src/multiarray/item_selection.c
@@ -1885,6 +1885,7 @@ PyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)
/* For backwards compatibility, during the deprecation period: */
copy = PyArray_NewCopy(ret, NPY_KEEPORDER);
+ Py_DECREF(ret);
if (!copy) {
return NULL;
}
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 118f221ae..e554d79fc 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -1028,6 +1028,13 @@ class TestMethods(TestCase):
assert_equal(collect_warning_types(getattr, ro_diag,
"__array_struct__"), [])
+ def test_diagonal_memleak(self):
+ # Regression test for a bug that crept in at one point
+ a = np.zeros((100, 100))
+ assert_(sys.getrefcount(a) < 50)
+ for i in xrange(100):
+ a.diagonal()
+ assert_(sys.getrefcount(a) < 50)
def test_ravel(self):
a = np.array([[0,1],[2,3]])