[Numpy-svn] r4897 - in trunk/numpy/core: src tests

numpy-svn at scipy.org numpy-svn at scipy.org
Wed Mar 19 20:12:20 EDT 2008


Author: stefan
Date: 2008-03-19 19:12:12 -0500 (Wed, 19 Mar 2008)
New Revision: 4897

Modified:
   trunk/numpy/core/src/multiarraymodule.c
   trunk/numpy/core/tests/test_regression.py
Log:
Fix memory leaks as reported in #562.  Patch by Matthieu Brucher.


Modified: trunk/numpy/core/src/multiarraymodule.c
===================================================================
--- trunk/numpy/core/src/multiarraymodule.c	2008-03-19 15:10:11 UTC (rev 4896)
+++ trunk/numpy/core/src/multiarraymodule.c	2008-03-20 00:12:12 UTC (rev 4897)
@@ -5663,7 +5663,6 @@
                 ret = PyArray_NewCopy((PyArrayObject*)op,
                                       order);
                 if (oldtype == type) goto finish;
-                Py_INCREF(oldtype);
                 Py_DECREF(PyArray_DESCR(ret));
                 PyArray_DESCR(ret) = oldtype;
                 goto finish;
@@ -5691,6 +5690,7 @@
     ret = PyArray_CheckFromAny(op, type, 0, 0, flags, NULL);
 
  finish:
+    Py_XDECREF(oldtype);
     if (!ret || (nd=PyArray_NDIM(ret)) >= ndmin) return ret;
     /* create a new array from the same data with ones in the shape */
     /* steals a reference to ret */

Modified: trunk/numpy/core/tests/test_regression.py
===================================================================
--- trunk/numpy/core/tests/test_regression.py	2008-03-19 15:10:11 UTC (rev 4896)
+++ trunk/numpy/core/tests/test_regression.py	2008-03-20 00:12:12 UTC (rev 4897)
@@ -818,5 +818,11 @@
         """Ticket #658"""
         np.indices((0,3,4)).T.reshape(-1,3)
 
+    def check_mem_deallocation_leak(self, level=rlevel):
+        """Ticket #562"""
+        a = np.zeros(5,dtype=float)
+        b = np.array(a,dtype=float)
+        del a, b
+
 if __name__ == "__main__":
     NumpyTest().run()




More information about the Numpy-svn mailing list