]> granicus.if.org Git - python/commitdiff
Issue #18408: Fix bytearrayiter.partition()/rpartition(), handle
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 29 Oct 2013 02:15:37 +0000 (03:15 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 29 Oct 2013 02:15:37 +0000 (03:15 +0100)
PyByteArray_FromStringAndSize() failure (ex: on memory allocation failure)

Objects/stringlib/partition.h

index 40cb5129d5d9780926092f5901aba881ee600149..ed32a6f2b382ec14bb4b46f03037001fe6ed2fec 100644 (file)
@@ -29,6 +29,11 @@ STRINGLIB(partition)(PyObject* str_obj,
         PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, str_len));
         PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0));
         PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(NULL, 0));
+
+        if (PyErr_Occurred()) {
+            Py_DECREF(out);
+            return NULL;
+        }
 #else
         Py_INCREF(str_obj);
         PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj);
@@ -79,6 +84,11 @@ STRINGLIB(rpartition)(PyObject* str_obj,
         PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(NULL, 0));
         PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0));
         PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str, str_len));
+
+        if (PyErr_Occurred()) {
+            Py_DECREF(out);
+            return NULL;
+        }
 #else
         Py_INCREF(STRINGLIB_EMPTY);
         PyTuple_SET_ITEM(out, 0, (PyObject*) STRINGLIB_EMPTY);