summaryrefslogtreecommitdiffstats
path: root/Python/pystate.c
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-08-12 08:46:02 (GMT)
committerGeorg Brandl <georg@python.org>2008-08-12 08:46:02 (GMT)
commit032215451bd9a8fc3a068e8a77871277e0f162d8 (patch)
tree1fd5ea775660621f39392ac6d84a376bd4341342 /Python/pystate.c
parent1576bab04203f18b7ce8fdf38aa24c4efbba8b3c (diff)
downloadcpython-032215451bd9a8fc3a068e8a77871277e0f162d8.zip
cpython-032215451bd9a8fc3a068e8a77871277e0f162d8.tar.gz
cpython-032215451bd9a8fc3a068e8a77871277e0f162d8.tar.bz2
Backport r60148 and r65481: sanity checks to avoid infinite loops.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r--Python/pystate.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index 086789d..da417c1 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -240,6 +240,7 @@ tstate_delete_common(PyThreadState *tstate)
{
PyInterpreterState *interp;
PyThreadState **p;
+ PyThreadState *prev_p = NULL;
if (tstate == NULL)
Py_FatalError("PyThreadState_Delete: NULL tstate");
interp = tstate->interp;
@@ -252,6 +253,19 @@ tstate_delete_common(PyThreadState *tstate)
"PyThreadState_Delete: invalid tstate");
if (*p == tstate)
break;
+ /* Sanity check. These states should never happen but if
+ * they do we must abort. Otherwise we'll end up spinning in
+ * in a tight loop with the lock held. A similar check is done
+ * in thread.c find_key(). */
+ if (*p == prev_p)
+ Py_FatalError(
+ "PyThreadState_Delete: small circular list(!)"
+ " and tstate not found.");
+ prev_p = *p;
+ if ((*p)->next == interp->tstate_head)
+ Py_FatalError(
+ "PyThreadState_Delete: circular list(!) and"
+ " tstate not found.");
}
*p = tstate->next;
HEAD_UNLOCK();