Skip to content

Commit c831298

Browse files
committed
Merge pull request numpy#3631 from charris/fix-reference-leak
Fix reference leak
2 parents 0a6217d + d0bdae4 commit c831298

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

numpy/core/src/multiarray/conversion_utils.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ PyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)
9999
/*
100100
* After the deprecation the PyNumber_Check could be replaced
101101
* by PyIndex_Check.
102+
* FIXME 1.9 ?
102103
*/
103104
len = 1;
104105
}
@@ -922,8 +923,8 @@ PyArray_IntpFromIndexSequence(PyObject *seq, npy_intp *vals, npy_intp maxvals)
922923
return -1;
923924
}
924925

925-
926926
vals[i] = PyArray_PyIntAsIntp(op);
927+
Py_DECREF(op);
927928
if(vals[i] == -1) {
928929
err = PyErr_Occurred();
929930
if (err &&

numpy/core/tests/test_numeric.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,20 @@ def test_filled(self):
15461546
self.check_function(np.full, 0)
15471547
self.check_function(np.full, 1)
15481548

1549+
def test_for_reference_leak(self):
1550+
# Make sure we have an object for reference
1551+
dim = 1
1552+
beg = sys.getrefcount(dim)
1553+
np.zeros([dim]*10)
1554+
assert_(sys.getrefcount(dim) == beg)
1555+
np.ones([dim]*10)
1556+
assert_(sys.getrefcount(dim) == beg)
1557+
np.empty([dim]*10)
1558+
assert_(sys.getrefcount(dim) == beg)
1559+
np.full([dim]*10, 0)
1560+
assert_(sys.getrefcount(dim) == beg)
1561+
1562+
15491563

15501564
class TestLikeFuncs(TestCase):
15511565
'''Test ones_like, zeros_like, empty_like and full_like'''

0 commit comments

Comments
 (0)