]> granicus.if.org Git - python/commitdiff
Issue #18203: Fix Py_Finalize(): destroy the GIL after the last call to
authorVictor Stinner <victor.stinner@gmail.com>
Sun, 7 Jul 2013 13:50:49 +0000 (15:50 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Sun, 7 Jul 2013 13:50:49 +0000 (15:50 +0200)
PyMem_Malloc() or PyObject_Malloc().

For example, PyCFunction_Fini() calls PyObject_GC_Del() which calls
PyObject_FREE().

Python/pythonrun.c

index 02a43299504c4ffaead1b038092b98dae0c9925e..94175be87e95476d43a2c78eed8d17a14eb07a23 100644 (file)
@@ -606,11 +606,6 @@ Py_Finalize(void)
 
     _PyExc_Fini();
 
-    /* Cleanup auto-thread-state */
-#ifdef WITH_THREAD
-    _PyGILState_Fini();
-#endif /* WITH_THREAD */
-
     /* Sundry finalizers */
     PyMethod_Fini();
     PyFrame_Fini();
@@ -629,10 +624,6 @@ Py_Finalize(void)
     /* Cleanup Unicode implementation */
     _PyUnicode_Fini();
 
-    /* Delete current thread. After this, many C API calls become crashy. */
-    PyThreadState_Swap(NULL);
-    PyInterpreterState_Delete(interp);
-
     /* reset file system default encoding */
     if (!Py_HasFileSystemDefaultEncoding && Py_FileSystemDefaultEncoding) {
         free((char*)Py_FileSystemDefaultEncoding);
@@ -647,6 +638,15 @@ Py_Finalize(void)
 
     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
     /* Display addresses (& refcnts) of all objects still alive.
      * An address can be used to find the repr of the object, printed