Commit 51fa458d authored by Victor Stinner's avatar Victor Stinner

Issue #18203: Fix Py_Finalize(): destroy the GIL after the last call to

PyMem_Malloc() or PyObject_Malloc().

For example, PyCFunction_Fini() calls PyObject_GC_Del() which calls
PyObject_FREE().
parent b385529d
...@@ -606,11 +606,6 @@ Py_Finalize(void) ...@@ -606,11 +606,6 @@ Py_Finalize(void)
_PyExc_Fini(); _PyExc_Fini();
/* Cleanup auto-thread-state */
#ifdef WITH_THREAD
_PyGILState_Fini();
#endif /* WITH_THREAD */
/* Sundry finalizers */ /* Sundry finalizers */
PyMethod_Fini(); PyMethod_Fini();
PyFrame_Fini(); PyFrame_Fini();
...@@ -629,10 +624,6 @@ Py_Finalize(void) ...@@ -629,10 +624,6 @@ Py_Finalize(void)
/* Cleanup Unicode implementation */ /* Cleanup Unicode implementation */
_PyUnicode_Fini(); _PyUnicode_Fini();
/* Delete current thread. After this, many C API calls become crashy. */
PyThreadState_Swap(NULL);
PyInterpreterState_Delete(interp);
/* reset file system default encoding */ /* reset file system default encoding */
if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding) { if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding) {
free((char*)Py_FileSystemDefaultEncoding); free((char*)Py_FileSystemDefaultEncoding);
...@@ -647,6 +638,15 @@ Py_Finalize(void) ...@@ -647,6 +638,15 @@ Py_Finalize(void)
PyGrammar_RemoveAccelerators(&_PyParser_Grammar); PyGrammar_RemoveAccelerators(&_PyParser_Grammar);
/* Cleanup auto-thread-state */
#ifdef WITH_THREAD
_PyGILState_Fini();
#endif /* WITH_THREAD */
/* Delete current thread. After this, many C API calls become crashy. */
PyThreadState_Swap(NULL);
PyInterpreterState_Delete(interp);
#ifdef Py_TRACE_REFS #ifdef Py_TRACE_REFS
/* Display addresses (& refcnts) of all objects still alive. /* Display addresses (& refcnts) of all objects still alive.
* An address can be used to find the repr of the object, printed * An address can be used to find the repr of the object, printed
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment