summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/iobase.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c
index 75cfe59..1a687c5 100644
--- a/Modules/_io/iobase.c
+++ b/Modules/_io/iobase.c
@@ -643,7 +643,7 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint)
/*[clinic end generated code: output=2f50421677fa3dea input=9400c786ea9dc416]*/
{
Py_ssize_t length = 0;
- PyObject *result;
+ PyObject *result, *it = NULL;
result = PyList_New(0);
if (result == NULL)
@@ -658,19 +658,22 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint)
self, NULL);
if (ret == NULL) {
- Py_DECREF(result);
- return NULL;
+ goto error;
}
Py_DECREF(ret);
return result;
}
+ it = PyObject_GetIter(self);
+ if (it == NULL) {
+ goto error;
+ }
+
while (1) {
- PyObject *line = PyIter_Next(self);
+ PyObject *line = PyIter_Next(it);
if (line == NULL) {
if (PyErr_Occurred()) {
- Py_DECREF(result);
- return NULL;
+ goto error;
}
else
break; /* StopIteration raised */
@@ -678,8 +681,7 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint)
if (PyList_Append(result, line) < 0) {
Py_DECREF(line);
- Py_DECREF(result);
- return NULL;
+ goto error;
}
length += PyObject_Size(line);
Py_DECREF(line);
@@ -687,7 +689,14 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint)
if (length > hint)
break;
}
+
+ Py_DECREF(it);
return result;
+
+ error:
+ Py_XDECREF(it);
+ Py_DECREF(result);
+ return NULL;
}
/*[clinic input]