Mercurial > cpython-lru_cache-weakref
diff Python/pystate.c @ 48217:eefe4450f773 2.5
Backport r60148 and r65481: sanity checks to avoid infinite loops.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Tue, 12 Aug 2008 08:46:02 +0000 |
| parents | 66f265ac4ec4 |
| children | 787b969d37f0 |
line wrap: on
line diff
--- a/Python/pystate.c Tue Aug 12 08:39:33 2008 +0000 +++ b/Python/pystate.c Tue Aug 12 08:46:02 2008 +0000 @@ -240,6 +240,7 @@ { PyInterpreterState *interp; PyThreadState **p; + PyThreadState *prev_p = NULL; if (tstate == NULL) Py_FatalError("PyThreadState_Delete: NULL tstate"); interp = tstate->interp; @@ -252,6 +253,19 @@ "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();
