[Numpy-discussion] Another reference count leak: ticket #848
Michael Abbott
michael at araneidae.co.uk
Tue Jul 8 05:35:40 EDT 2008
The attached patch fixes another reference count leak in the use of
PyArray_DescrFromType.
Could I ask that both this patch and my earlier one (ticket #843) be
applied to subversion. Thank you.
Definitely not enjoying this low level code.
commit 80e1aca1725dd4cd8e091126cf515c39ac3a33ff
Author: Michael Abbott <michael.abbott at diamond.ac.uk>
Date: Tue Jul 8 10:10:59 2008 +0100
Another reference leak using PyArray_DescrFromType
This change fixes two issues: a spurious ADDREF on a typecode returned
from PyArray_DescrFromType and a return path with no DECREF.
diff --git a/numpy/core/src/scalartypes.inc.src b/numpy/core/src/scalartypes.inc.src
index 3feefc0..772cf94 100644
--- a/numpy/core/src/scalartypes.inc.src
+++ b/numpy/core/src/scalartypes.inc.src
@@ -1886,7 +1886,6 @@ static PyObject *
if (!PyArg_ParseTuple(args, "|O", &obj)) return NULL;
typecode = PyArray_DescrFromType(PyArray_ at TYPE@);
- Py_INCREF(typecode);
if (obj == NULL) {
#if @default@ == 0
char *mem;
@@ -1904,7 +1903,10 @@ static PyObject *
}
arr = PyArray_FromAny(obj, typecode, 0, 0, FORCECAST, NULL);
- if ((arr==NULL) || (PyArray_NDIM(arr) > 0)) return arr;
+ if ((arr==NULL) || (PyArray_NDIM(arr) > 0)) {
+ Py_XDECREF(typecode);
+ return arr;
+ }
robj = PyArray_Return((PyArrayObject *)arr);
finish:
More information about the NumPy-Discussion
mailing list