gh-120754: Fix memory leak in FileIO.__init__() - #124225
Conversation
Free 'self->stat_atopen' before assigning it, since io.FileIO.__init__() can be called multiple times manually (especially by test_io).
|
👍 Definitely where the leak is happening / my own tracking finds same location. https://vstinner.github.io/debug-python-refleak.html really helpful in tracking down, thanks for writing up. There's a number of cases where |
|
Only allocating (PyMem_New) You might include your better fix in a following PR if you want, since you planned more changes for io if I understood correctly. Thanks for reviewing my fix! |
Free 'self->stat_atopen' before assigning it, since io.FileIO.__init__() can be called multiple times manually (especially by test_io).

Free 'self->stat_atopen' before assigning it, since io.FileIO.init() can be called multiple times manually (especially by test_io).