summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2017-08-30 08:40:48 -0500
committerGitHub <noreply@github.com>2017-08-30 08:40:48 -0500
commitf785875f81727a3b9c6c67a7e6962183bbe19f28 (patch)
tree07346f5eff24a1f961946c3b35ceadcdd8618a21 /numpy
parent0032e535f7ebbcb4528dbbedb9c71b47914071c7 (diff)
parentdaf7a4e33168aeec05ad2217b49550bfab3d18d9 (diff)
downloadnumpy-f785875f81727a3b9c6c67a7e6962183bbe19f28.tar.gz
Merge pull request #9624 from ExpHP/dot-memory-leak
BUG: memory leak in np.dot of size 0
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/cblasfuncs.c3
-rw-r--r--numpy/core/tests/test_multiarray.py11
2 files changed, 13 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/cblasfuncs.c b/numpy/core/src/multiarray/cblasfuncs.c
index 3b0b2f4f6..8432ae5cf 100644
--- a/numpy/core/src/multiarray/cblasfuncs.c
+++ b/numpy/core/src/multiarray/cblasfuncs.c
@@ -456,7 +456,8 @@ cblas_matrixproduct(int typenum, PyArrayObject *ap1, PyArrayObject *ap2,
if (numbytes == 0 || l == 0) {
Py_DECREF(ap1);
Py_DECREF(ap2);
- return PyArray_Return(out_buf);
+ Py_DECREF(out_buf);
+ return PyArray_Return(result);
}
if (ap2shape == _scalar) {
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index ba4b0e0d8..74f6a3af9 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -2497,6 +2497,17 @@ class TestMethods(object):
if HAS_REFCOUNT:
assert_(sys.getrefcount(a) < 50)
+ def test_size_zero_memleak(self):
+ # Regression test for issue 9615
+ # Exercises a special-case code path for dot products of length
+ # zero in cblasfuncs (making it is specific to floating dtypes).
+ a = np.array([], dtype=np.float64)
+ x = np.array(2.0)
+ for _ in range(100):
+ np.dot(a, a, out=x)
+ if HAS_REFCOUNT:
+ assert_(sys.getrefcount(x) < 50)
+
def test_trace(self):
a = np.arange(12).reshape((3, 4))
assert_equal(a.trace(), 15)