gh-120754: Fix memory leak in FileIO.__init__() (#124225)

Free 'self->stat_atopen' before assigning it, since
io.FileIO.__init__() can be called multiple times manually
(especially by test_io).
This commit is contained in:
Victor Stinner 2024-09-19 00:11:50 +02:00 committed by GitHub
parent ea7fe1fe2e
commit 43cd7aa8cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 1 additions and 0 deletions

View File

@ -457,6 +457,7 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
#endif
}
PyMem_Free(self->stat_atopen);
self->stat_atopen = PyMem_New(struct _Py_stat_struct, 1);
if (self->stat_atopen == NULL) {
PyErr_NoMemory();