[Python-checkins] cpython (2.7): Issue #17703: Fix a regression where an illegal use of Py_DECREF() after

antoine.pitrou python-checkins at python.org
Mon Apr 15 21:20:27 CEST 2013


http://hg.python.org/cpython/rev/e814fbd470bf
changeset:   83398:e814fbd470bf
branch:      2.7
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Mon Apr 15 21:20:14 2013 +0200
summary:
  Issue #17703: Fix a regression where an illegal use of Py_DECREF() after interpreter finalization can cause a crash.

files:
  Include/object.h |  16 +++++++++++-----
  Misc/NEWS        |   3 +++
  2 files changed, 14 insertions(+), 5 deletions(-)


diff --git a/Include/object.h b/Include/object.h
--- a/Include/object.h
+++ b/Include/object.h
@@ -984,16 +984,22 @@
 
 #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); \
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -17,6 +17,9 @@
 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.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list