[issue43260] Never release buffer when MemoryError in print()
Inada Naoki
report at bugs.python.org
Fri Feb 19 23:53:52 EST 2021
Inada Naoki <songofacandy at gmail.com> added the comment:
In your code, huge data passed to .write(huge) may be remained in the internal buffer.
```
[NEW PRE-FLUSH]
else if ((self->pending_bytes_count + bytes_len) > self->chunk_size) {
if (_textiowrapper_writeflush(self) < 0) {
Py_DECREF(b);
return NULL;
}
self->pending_bytes = b;
}
(snip)
self->pending_bytes_count += bytes_len;
if (self->pending_bytes_count > self->chunk_size || needflush ||
text_needflush) {
if (_textiowrapper_writeflush(self) < 0)
return NULL;
}
```
In my opinion, when .write(huge) fails with MemoryError, TextIOWrapper must not keep the `huge` in the internal buffer.
See my PR-24592.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43260>
_______________________________________
More information about the Python-bugs-list
mailing list