summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2009-12-03 03:20:56 +0000
committerTravis Oliphant <oliphant@enthought.com>2009-12-03 03:20:56 +0000
commit2f300ed50be961076a28c60a7227233ce72975aa (patch)
tree91e9a7549c4a29c629595ec2e79214f3a2d411c4 /numpy
parentfd0866ffc7ca4c3d843b156c9a706b1a3e1ad67d (diff)
downloadnumpy-2f300ed50be961076a28c60a7227233ce72975aa.tar.gz
Push memory-leak fix to trunk.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/ctors.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index a2eb4494b..c6833d256 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -921,32 +921,37 @@ static int
setArrayFromSequence(PyArrayObject *a, PyObject *s, int dim, intp offset)
{
Py_ssize_t i, slen;
- int res = 0;
+ int res = -1;
/*
* This code is to ensure that the sequence access below will
* return a lower-dimensional sequence.
*/
+
+ /* INCREF on entry DECREF on exit */
+ Py_INCREF(s);
+
if (PyArray_Check(s) && !(PyArray_CheckExact(s))) {
/*
* FIXME: This could probably copy the entire subarray at once here using
* a faster algorithm. Right now, just make sure a base-class array is
* used so that the dimensionality reduction assumption is correct.
*/
+ /* This will DECREF(s) if replaced */
s = PyArray_EnsureArray(s);
}
if (dim > a->nd) {
PyErr_Format(PyExc_ValueError,
"setArrayFromSequence: sequence/array dimensions mismatch.");
- return -1;
+ goto fail;
}
slen = PySequence_Length(s);
if (slen != a->dimensions[dim]) {
PyErr_Format(PyExc_ValueError,
"setArrayFromSequence: sequence/array shape mismatch.");
- return -1;
+ goto fail;
}
for (i = 0; i < slen; i++) {
@@ -959,11 +964,17 @@ setArrayFromSequence(PyArrayObject *a, PyObject *s, int dim, intp offset)
}
Py_DECREF(o);
if (res < 0) {
- return res;
+ goto fail;
}
offset += a->strides[dim];
}
+
+ Py_DECREF(s);
return 0;
+
+ fail:
+ Py_DECREF(s);
+ return res;
}
static int