]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-120754: Fix memory leak in FileIO.__init__() (#124225)
authorVictor Stinner <vstinner@python.org>
Wed, 18 Sep 2024 22:11:50 +0000 (00:11 +0200)
committerGitHub <noreply@github.com>
Wed, 18 Sep 2024 22:11:50 +0000 (00:11 +0200)
Free 'self->stat_atopen' before assigning it, since
io.FileIO.__init__() can be called multiple times manually
(especially by test_io).

Modules/_io/fileio.c

index 865b0e3634f3b4e9579148aa5aadb955bc2ccf07..8dae465fd20f8b09dccbfb5692398969838ba47b 100644 (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();