mirror of
https://github.com/python/cpython.git
synced 2025-07-12 13:55:34 +00:00
Closes #15488: Closed files keep their buffer alive
This commit is contained in:
parent
279ed3cc55
commit
dc469454ec
3 changed files with 16 additions and 0 deletions
|
@ -815,6 +815,14 @@ class SizeofTest:
|
||||||
bufio = self.tp(rawio, buffer_size=bufsize2)
|
bufio = self.tp(rawio, buffer_size=bufsize2)
|
||||||
self.assertEqual(sys.getsizeof(bufio), size + bufsize2)
|
self.assertEqual(sys.getsizeof(bufio), size + bufsize2)
|
||||||
|
|
||||||
|
@support.cpython_only
|
||||||
|
def test_buffer_freeing(self) :
|
||||||
|
bufsize = 4096
|
||||||
|
rawio = self.MockRawIO()
|
||||||
|
bufio = self.tp(rawio, buffer_size=bufsize)
|
||||||
|
size = sys.getsizeof(bufio) - bufsize
|
||||||
|
bufio.close()
|
||||||
|
self.assertEqual(sys.getsizeof(bufio), size)
|
||||||
|
|
||||||
class BufferedReaderTest(unittest.TestCase, CommonBufferedTests):
|
class BufferedReaderTest(unittest.TestCase, CommonBufferedTests):
|
||||||
read_mode = "rb"
|
read_mode = "rb"
|
||||||
|
|
|
@ -24,6 +24,9 @@ Core and Builtins
|
||||||
|
|
||||||
- Issue #15839: Convert SystemErrors in `super()` to RuntimeErrors.
|
- Issue #15839: Convert SystemErrors in `super()` to RuntimeErrors.
|
||||||
|
|
||||||
|
- Issue #15448: Buffered IO now frees the buffer when closed, instead
|
||||||
|
of when deallocating.
|
||||||
|
|
||||||
- Issue #15846: Fix SystemError which happened when using `ast.parse()` in an
|
- Issue #15846: Fix SystemError which happened when using `ast.parse()` in an
|
||||||
exception handler on code with syntax errors.
|
exception handler on code with syntax errors.
|
||||||
|
|
||||||
|
|
|
@ -519,6 +519,11 @@ buffered_close(buffered *self, PyObject *args)
|
||||||
|
|
||||||
res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_close, NULL);
|
res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_close, NULL);
|
||||||
|
|
||||||
|
if (self->buffer) {
|
||||||
|
PyMem_Free(self->buffer);
|
||||||
|
self->buffer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
LEAVE_BUFFERED(self)
|
LEAVE_BUFFERED(self)
|
||||||
return res;
|
return res;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue