bpo-40887: Fix finalize_interp_clear() for free lists (GH-20698)

Reorganize code to ensure that free lists are cleared in the right
order. Call _PyWarnings_Fini() before _PyList_Fini().
This commit is contained in:
Victor Stinner 2020-06-08 01:22:36 +02:00 committed by GitHub
parent 2efe18bf27
commit 7907f8cbc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 33 deletions

View File

@ -1250,37 +1250,26 @@ static void
finalize_interp_types(PyThreadState *tstate, int is_main_interp) finalize_interp_types(PyThreadState *tstate, int is_main_interp)
{ {
_PyFrame_Fini(tstate); _PyFrame_Fini(tstate);
_PyTuple_Fini(tstate);
_PyList_Fini(tstate);
if (is_main_interp) {
_PySet_Fini();
_PyBytes_Fini();
}
_PyLong_Fini(tstate);
_PyFloat_Fini(tstate);
if (is_main_interp) {
_PyDict_Fini();
}
_PySlice_Fini(tstate);
_PyWarnings_Fini(tstate->interp);
if (is_main_interp) {
_Py_HashRandomization_Fini();
_PyArg_Fini();
}
_PyAsyncGen_Fini(tstate); _PyAsyncGen_Fini(tstate);
_PyContext_Fini(tstate); _PyContext_Fini(tstate);
/* Cleanup Unicode implementation */ if (is_main_interp) {
_PyUnicode_Fini(tstate); _PySet_Fini();
}
if (is_main_interp) {
_PyDict_Fini();
}
_PyList_Fini(tstate);
_PyTuple_Fini(tstate);
_PySlice_Fini(tstate);
if (is_main_interp) { if (is_main_interp) {
_Py_ClearFileSystemEncoding(); _PyBytes_Fini();
} }
_PyUnicode_Fini(tstate);
_PyFloat_Fini(tstate);
_PyLong_Fini(tstate);
} }
@ -1299,19 +1288,20 @@ finalize_interp_clear(PyThreadState *tstate)
_PyGC_Fini(tstate); _PyGC_Fini(tstate);
finalize_interp_types(tstate, is_main_interp); if (is_main_interp) {
_Py_HashRandomization_Fini();
_PyArg_Fini();
_Py_ClearFileSystemEncoding();
}
_PyWarnings_Fini(tstate->interp);
if (is_main_interp) { if (is_main_interp) {
/* XXX Still allocated:
- various static ad-hoc pointers to interned strings
- int and float free list blocks
- whatever various modules and libraries allocate
*/
PyGrammar_RemoveAccelerators(&_PyParser_Grammar); PyGrammar_RemoveAccelerators(&_PyParser_Grammar);
_PyExc_Fini(); _PyExc_Fini();
} }
finalize_interp_types(tstate, is_main_interp);
} }