Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BUG: Fix memory leak in PyArray_Diagonal

Thanks to Gael Varoquaux for the catch.
  • Loading branch information...
commit 80b3a3401382cb3f14c5b76dd90d9f932f50ad15 1 parent 9597b1f
@njsmith njsmith authored
View
1  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;
}
View
7 numpy/core/tests/test_multiarray.py
@@ -1028,6 +1028,13 @@ def get_data_and_write(getter):
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]])
Please sign in to comment.
Something went wrong with that request. Please try again.