bpo-46417: Clear _io module static objects at exit (GH-30807)

Add _PyIO_Fini() function, called by finalize_interp_clear(). It
clears static objects used by the _io extension module.
This commit is contained in:
Victor Stinner 2022-01-22 23:22:20 +01:00 committed by GitHub
parent 1626bf4ac7
commit 9c8e490b8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 99 additions and 44 deletions

View file

@ -29,6 +29,8 @@
#include "pycore_typeobject.h" // _PyTypes_InitTypes()
#include "pycore_unicodeobject.h" // _PyUnicode_InitTypes()
extern void _PyIO_Fini(void);
#include <locale.h> // setlocale()
#include <stdlib.h> // getenv()
@ -1702,6 +1704,10 @@ finalize_interp_clear(PyThreadState *tstate)
/* Clear interpreter state and all thread states */
_PyInterpreterState_Clear(tstate);
if (is_main_interp) {
_PyIO_Fini();
}
/* Clear all loghooks */
/* Both _PySys_Audit function and users still need PyObject, such as tuple.
Call _PySys_ClearAuditHooks when PyObject available. */