File tree Expand file tree Collapse file tree 3 files changed +16
-0
lines changed
Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -815,6 +815,14 @@ def test_sizeof(self):
815815 bufio = self .tp (rawio , buffer_size = bufsize2 )
816816 self .assertEqual (sys .getsizeof (bufio ), size + bufsize2 )
817817
818+ @support .cpython_only
819+ def test_buffer_freeing (self ) :
820+ bufsize = 4096
821+ rawio = self .MockRawIO ()
822+ bufio = self .tp (rawio , buffer_size = bufsize )
823+ size = sys .getsizeof (bufio ) - bufsize
824+ bufio .close ()
825+ self .assertEqual (sys .getsizeof (bufio ), size )
818826
819827class BufferedReaderTest (unittest .TestCase , CommonBufferedTests ):
820828 read_mode = "rb"
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ Core and Builtins
2424
2525- Issue #15839: Convert SystemErrors in `super()` to RuntimeErrors.
2626
27+ - Issue #15448: Buffered IO now frees the buffer when closed, instead
28+ of when deallocating.
29+
2730- Issue #15846: Fix SystemError which happened when using `ast.parse()` in an
2831 exception handler on code with syntax errors.
2932
Original file line number Diff line number Diff line change @@ -519,6 +519,11 @@ buffered_close(buffered *self, PyObject *args)
519519
520520 res = PyObject_CallMethodObjArgs (self -> raw , _PyIO_str_close , NULL );
521521
522+ if (self -> buffer ) {
523+ PyMem_Free (self -> buffer );
524+ self -> buffer = NULL ;
525+ }
526+
522527end :
523528 LEAVE_BUFFERED (self )
524529 return res ;
You can’t perform that action at this time.
0 commit comments