Commit 909b30e9 authored by Joseph Weston's avatar Joseph Weston
Browse files

move DECREF to correct place in code

Previously, load_index_seq_as_long did not correctly DECREF the
new reference created by PySequence_Fast, and I had erroneously
DECREF'd this reference in code which called load_index_seq_as_long.
parent a9c884d5
......@@ -1377,6 +1377,7 @@ int load_index_seq_as_long(PyObject *obj, long *out, int maxlen)
assert(maxlen >= 1);
int len;
if (PySequence_Check(obj)) {
// get a new reference -- don't forget to DECREF on all codepaths
obj = PySequence_Fast(obj, "Bug in tinyarray, load_index_seq_as_long");
if (!obj) return -1;
Py_ssize_t long_len = PySequence_Fast_GET_SIZE(obj);
......@@ -1394,6 +1395,7 @@ int load_index_seq_as_long(PyObject *obj, long *out, int maxlen)
Py_DECREF(index);
if (*out == -1 && PyErr_Occurred()) goto fail;
}
Py_DECREF(obj);
} else {
len = 1;
*out = PyInt_AsLong(obj);
......
......@@ -83,7 +83,6 @@ PyObject *reconstruct(PyObject *, PyObject *args)
unsigned long shape_as_ulong[max_ndim];
int ndim = load_index_seq_as_ulong(pyshape, shape_as_ulong, max_ndim,
"Negative dimensions are not allowed.");
Py_DECREF(pyshape);
if (ndim == -1) return 0;
size_t shape[max_ndim];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment