Skip to content

Commit 43cd7aa

Browse files
authored
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).
1 parent ea7fe1f commit 43cd7aa

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

Modules/_io/fileio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
457457
#endif
458458
}
459459

460+
PyMem_Free(self->stat_atopen);
460461
self->stat_atopen = PyMem_New(struct _Py_stat_struct, 1);
461462
if (self->stat_atopen == NULL) {
462463
PyErr_NoMemory();

0 commit comments

Comments
 (0)