summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-04-15 19:20:14 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-04-15 19:20:14 (GMT)
commit108d1b4a7962a7777b7fb6108f12df619ea9218b (patch)
treea8259f9977ddaf53229ba120c603f5c5deadac74
parent1b3320659667b688a3d5740d04e4b7480a09fcc3 (diff)
downloadcpython-108d1b4a7962a7777b7fb6108f12df619ea9218b.zip
cpython-108d1b4a7962a7777b7fb6108f12df619ea9218b.tar.gz
cpython-108d1b4a7962a7777b7fb6108f12df619ea9218b.tar.bz2
Issue #17703: Fix a regression where an illegal use of Py_DECREF() after interpreter finalization can cause a crash.
-rw-r--r--Include/object.h16
-rw-r--r--Misc/NEWS3
2 files changed, 14 insertions, 5 deletions
diff --git a/Include/object.h b/Include/object.h
index 1ba33eb..afbc68d 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -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); \
diff --git a/Misc/NEWS b/Misc/NEWS
index d723cb5..3ccdb10 100644
--- 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.