[Python-checkins] r64220 - python/trunk/Modules/arraymodule.c

neal.norwitz python-checkins at python.org
Fri Jun 13 08:02:26 CEST 2008


Author: neal.norwitz
Date: Fri Jun 13 08:02:26 2008
New Revision: 64220

Log:
Fix some memory dealloc problems when exceptions occur.
It caused: "Fatal Python error: UNREF invalid object" in the DoubleTest.


Modified:
   python/trunk/Modules/arraymodule.c

Modified: python/trunk/Modules/arraymodule.c
==============================================================================
--- python/trunk/Modules/arraymodule.c	(original)
+++ python/trunk/Modules/arraymodule.c	Fri Jun 13 08:02:26 2008
@@ -432,6 +432,9 @@
 	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 @@
 	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 @@
 	}
 	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,


More information about the Python-checkins mailing list