Message263083
| Author |
martin.panter |
| Recipients |
martin.panter |
| Date |
2016年04月09日.12:08:45 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1460203726.07.0.470306343445.issue26720@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
>>> 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). |
|
History
|
|---|
| 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 |
|