summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-09-18 22:11:50 (GMT)
committerGitHub <noreply@github.com>2024-09-18 22:11:50 (GMT)
commit43cd7aa8cd88624f7211e47b98bc1e8e63e7660f (patch)
tree2281a676a2346988f7ec70f9884c322ac245212e /Modules
parentea7fe1fe2e162f2375562467ad834c6224a62daf (diff)
downloadcpython-43cd7aa8cd88624f7211e47b98bc1e8e63e7660f.zip
cpython-43cd7aa8cd88624f7211e47b98bc1e8e63e7660f.tar.gz
cpython-43cd7aa8cd88624f7211e47b98bc1e8e63e7660f.tar.bz2
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).
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/fileio.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 865b0e3..8dae465 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -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();