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):
815
815
bufio = self .tp (rawio , buffer_size = bufsize2 )
816
816
self .assertEqual (sys .getsizeof (bufio ), size + bufsize2 )
817
817
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 )
818
826
819
827
class BufferedReaderTest (unittest .TestCase , CommonBufferedTests ):
820
828
read_mode = "rb"
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ Core and Builtins
24
24
25
25
- Issue #15839: Convert SystemErrors in `super()` to RuntimeErrors.
26
26
27
+ - Issue #15448: Buffered IO now frees the buffer when closed, instead
28
+ of when deallocating.
29
+
27
30
- Issue #15846: Fix SystemError which happened when using `ast.parse()` in an
28
31
exception handler on code with syntax errors.
29
32
Original file line number Diff line number Diff line change @@ -519,6 +519,11 @@ buffered_close(buffered *self, PyObject *args)
519
519
520
520
res = PyObject_CallMethodObjArgs (self -> raw , _PyIO_str_close , NULL );
521
521
522
+ if (self -> buffer ) {
523
+ PyMem_Free (self -> buffer );
524
+ self -> buffer = NULL ;
525
+ }
526
+
522
527
end :
523
528
LEAVE_BUFFERED (self )
524
529
return res ;
You can’t perform that action at this time.
0 commit comments