summaryrefslogtreecommitdiff
path: root/Python/thread.c
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-08-12 08:46:02 +0000
committerGeorg Brandl <georg@python.org>2008-08-12 08:46:02 +0000
commit032215451bd9a8fc3a068e8a77871277e0f162d8 (patch)
tree1fd5ea775660621f39392ac6d84a376bd4341342 /Python/thread.c
parent1576bab04203f18b7ce8fdf38aa24c4efbba8b3c (diff)
downloadcpython-git-032215451bd9a8fc3a068e8a77871277e0f162d8.tar.gz
Backport r60148 and r65481: sanity checks to avoid infinite loops.
Diffstat (limited to 'Python/thread.c')
-rw-r--r--Python/thread.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/Python/thread.c b/Python/thread.c
index 3a2c7af6ff..be4d092bcc 100644
--- a/Python/thread.c
+++ b/Python/thread.c
@@ -264,15 +264,25 @@ static int nkeys = 0; /* PyThread_create_key() hands out nkeys+1 next */
static struct key *
find_key(int key, void *value)
{
- struct key *p;
+ struct key *p, *prev_p;
long id = PyThread_get_thread_ident();
if (!keymutex)
return NULL;
PyThread_acquire_lock(keymutex, 1);
+ prev_p = NULL;
for (p = keyhead; p != NULL; p = p->next) {
if (p->id == id && p->key == key)
goto Done;
+ /* 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 pystate.c tstate_delete_common(). */
+ if (p == prev_p)
+ Py_FatalError("tls find_key: small circular list(!)");
+ prev_p = p;
+ if (p->next == keyhead)
+ Py_FatalError("tls find_key: circular list(!)");
}
if (value == NULL) {
assert(p == NULL);