This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author martin.panter
Recipients martin.panter
Date 2016-04-09.12:08:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
>>> class Raw(RawIOBase):
...     def writable(self): return True
...     def write(self, b):
...         global written
...         written = b
...         return len(b)
>>> writer = BufferedWriter(Raw())
>>> writer.write(b"blaua")
>>> raw = writer.detach()
>>> written
<memory at 0x7fd37f7b1aa8>
>>> written.tobytes()
>>> del writer
>>> written.tobytes()  # Garbage

Assuming this is pointing into unallocated memory, maybe it could trigger a segfault, though I haven’t seen that.

I haven’t looked at the implementation. But I am guessing that BufferedWriter is passing a view of its internal buffer to write(). For Python 2, perhaps the fix is to check if that memoryview is still referenced, and allocate a new buffer if so. 3.5 should probably inherit this fix.

Another option for 3.6 might be to call release() when write() returns. This should be documented (along with the fact that memoryview is possible in the first place; see Issue 20699).
Date User Action Args
2016-04-09 12:08:46martin.pantersetrecipients: + martin.panter
2016-04-09 12:08:46martin.pantersetmessageid: <>
2016-04-09 12:08:46martin.panterlinkissue26720 messages
2016-04-09 12:08:45martin.pantercreate