summaryrefslogtreecommitdiffstats
path: root/Modules/arraymodule.c
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2008-06-13 06:02:26 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2008-06-13 06:02:26 (GMT)
commit705cd06f9122897ca5137b4da0cb4f1f163a9ceb (patch)
tree0f9c82ab02ddee02ba0ae24231af8f73b36bd812 /Modules/arraymodule.c
parente9ee44c25b47e676b1b691cda5d75340b6f182fe (diff)
downloadcpython-705cd06f9122897ca5137b4da0cb4f1f163a9ceb.zip
cpython-705cd06f9122897ca5137b4da0cb4f1f163a9ceb.tar.gz
cpython-705cd06f9122897ca5137b4da0cb4f1f163a9ceb.tar.bz2
Fix some memory dealloc problems when exceptions occur.
It caused: "Fatal Python error: UNREF invalid object" in the DoubleTest.
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r--Modules/arraymodule.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index c505dad..5d10001 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -432,6 +432,9 @@ newarrayobject(PyTypeObject *type, Py_ssize_t size, struct arraydescr *descr)
if (op == NULL) {
return NULL;
}
+ op->ob_descr = descr;
+ op->allocated = size;
+ op->weakreflist = NULL;
Py_SIZE(op) = size;
if (size <= 0) {
op->ob_item = NULL;
@@ -439,13 +442,10 @@ newarrayobject(PyTypeObject *type, Py_ssize_t size, struct arraydescr *descr)
else {
op->ob_item = PyMem_NEW(char, nbytes);
if (op->ob_item == NULL) {
- PyObject_Del(op);
+ Py_DECREF(op);
return PyErr_NoMemory();
}
}
- op->ob_descr = descr;
- op->allocated = size;
- op->weakreflist = NULL;
return (PyObject *) op;
}
@@ -826,14 +826,13 @@ array_do_extend(arrayobject *self, PyObject *bb)
}
if ((Py_SIZE(self) > PY_SSIZE_T_MAX - Py_SIZE(b)) ||
((Py_SIZE(self) + Py_SIZE(b)) > PY_SSIZE_T_MAX / self->ob_descr->itemsize)) {
- PyErr_NoMemory();
- return -1;
+ PyErr_NoMemory();
+ return -1;
}
size = Py_SIZE(self) + Py_SIZE(b);
PyMem_RESIZE(self->ob_item, char, size*self->ob_descr->itemsize);
if (self->ob_item == NULL) {
- PyObject_Del(self);
- PyErr_NoMemory();
+ PyErr_NoMemory();
return -1;
}
memcpy(self->ob_item + Py_SIZE(self)*self->ob_descr->itemsize,