]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #17703: Fix a regression where an illegal use of Py_DECREF() after interpreter...
authorAntoine Pitrou <solipsis@pitrou.net>
Mon, 15 Apr 2013 19:20:14 +0000 (21:20 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Mon, 15 Apr 2013 19:20:14 +0000 (21:20 +0200)
Include/object.h
Misc/NEWS

index 1ba33eb6c1c1a10172be15357762195a415c3c88..afbc68dc04e9412134dfd60bd87608656e4d1e8b 100644 (file)
@@ -984,16 +984,22 @@ PyAPI_FUNC(void) _PyTrash_thread_destroy_chain(void);
 
 #define PyTrash_UNWIND_LEVEL 50
 
+/* Note the workaround for when the thread state is NULL (issue #17703) */
 #define Py_TRASHCAN_SAFE_BEGIN(op) \
     do { \
         PyThreadState *_tstate = PyThreadState_GET(); \
-        if (_tstate->trash_delete_nesting < PyTrash_UNWIND_LEVEL) { \
-            ++_tstate->trash_delete_nesting;
+        if (!_tstate || \
+            _tstate->trash_delete_nesting < PyTrash_UNWIND_LEVEL) { \
+            if (_tstate) \
+                ++_tstate->trash_delete_nesting;
             /* The body of the deallocator is here. */
 #define Py_TRASHCAN_SAFE_END(op) \
-            --_tstate->trash_delete_nesting; \
-            if (_tstate->trash_delete_later && _tstate->trash_delete_nesting <= 0) \
-                _PyTrash_thread_destroy_chain(); \
+            if (_tstate) { \
+                --_tstate->trash_delete_nesting; \
+                if (_tstate->trash_delete_later \
+                    && _tstate->trash_delete_nesting <= 0) \
+                    _PyTrash_thread_destroy_chain(); \
+            } \
         } \
         else \
             _PyTrash_thread_deposit_object((PyObject*)op); \
index d723cb59919a8b2c3526359adc03518c0b68a7b9..3ccdb10bfa52735fc612dcbf65d90bc2ce973f52 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -17,6 +17,9 @@ Build
 Core and Builtins
 -----------------
 
+- Issue #17703: Fix a regression where an illegal use of Py_DECREF() after
+  interpreter finalization can cause a crash.
+
 - Issue #16447: Fixed potential segmentation fault when setting __name__ on a
   class.