summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-10-29 02:15:37 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-10-29 02:15:37 (GMT)
commitcc64eb5b9feaf610e75565600f6c6331e8fbe8d4 (patch)
tree99fef7d579ce989ec22bf01c6a58e2dd2c7a2c2a
parent986e224d5a71342b683975ea0240315a8264616b (diff)
downloadcpython-cc64eb5b9feaf610e75565600f6c6331e8fbe8d4.zip
cpython-cc64eb5b9feaf610e75565600f6c6331e8fbe8d4.tar.gz
cpython-cc64eb5b9feaf610e75565600f6c6331e8fbe8d4.tar.bz2
Issue #18408: Fix bytearrayiter.partition()/rpartition(), handle
PyByteArray_FromStringAndSize() failure (ex: on memory allocation failure)
-rw-r--r--Objects/stringlib/partition.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/Objects/stringlib/partition.h b/Objects/stringlib/partition.h
index 40cb512..ed32a6f 100644
--- a/Objects/stringlib/partition.h
+++ b/Objects/stringlib/partition.h
@@ -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);