From 705cd06f9122897ca5137b4da0cb4f1f163a9ceb Mon Sep 17 00:00:00 2001 From: Neal Norwitz Date: Fri, 13 Jun 2008 06:02:26 +0000 Subject: [PATCH] Fix some memory dealloc problems when exceptions occur. It caused: "Fatal Python error: UNREF invalid object" in the DoubleTest. --- Modules/arraymodule.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index c505dadfc13..5d10001ab59 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,