Message263083
>>> 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")
5
>>> raw = writer.detach()
>>> written
<memory at 0x7fd37f7b1aa8>
>>> written.tobytes()
b'blaua'
>>> del writer
>>> written.tobytes() # Garbage
b'\x80f\xab\x00\x00'
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:46 | martin.panter | set | recipients:
+ martin.panter |
2016-04-09 12:08:46 | martin.panter | set | messageid: <1460203726.07.0.470306343445.issue26720@psf.upfronthosting.co.za> |
2016-04-09 12:08:46 | martin.panter | link | issue26720 messages |
2016-04-09 12:08:45 | martin.panter | create | |
|