Skip to content

Commit

Permalink
gh-120754: Fix memory leak in FileIO.__init__() (#124225)
Browse files Browse the repository at this point in the history
Free 'self->stat_atopen' before assigning it, since
io.FileIO.__init__() can be called multiple times manually
(especially by test_io).
  • Loading branch information
vstinner authored Sep 18, 2024
1 parent ea7fe1f commit 43cd7aa
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions Modules/_io/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 43cd7aa

Please sign in to comment.