diff Modules/arraymodule.c @ 84701:b05a6a6eb525

Issue #18408: Fix array_tolist(), handle PyList_SetItem() failure
author Victor Stinner <victor.stinner@gmail.com>
date Thu, 18 Jul 2013 01:12:35 +0200
parents d85b0c355052
children e7f6cef7a4cc
line wrap: on
line diff
--- a/Modules/arraymodule.c	Wed Jul 17 23:01:30 2013 +0200
+++ b/Modules/arraymodule.c	Thu Jul 18 01:12:35 2013 +0200
@@ -1027,7 +1027,7 @@
     for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(self); i++) {
         PyObject *selfi = getarrayitem((PyObject *)self, i);
         if (selfi == NULL)
-            return NULL;
+            return -1;
         cmp = PyObject_RichCompareBool(selfi, v, Py_EQ);
         Py_DECREF(selfi);
     }
@@ -1405,13 +1405,16 @@
         return NULL;
     for (i = 0; i < Py_SIZE(self); i++) {
         PyObject *v = getarrayitem((PyObject *)self, i);
-        if (v == NULL) {
-            Py_DECREF(list);
-            return NULL;
-        }
-        PyList_SetItem(list, i, v);
+        if (v == NULL)
+            goto error;
+        if (PyList_SetItem(list, i, v) < 0)
+            goto error;
     }
     return list;
+
+error:
+    Py_DECREF(list);
+    return NULL;
 }
 
 PyDoc_STRVAR(tolist_doc,