Merged revisions 75123 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r75123 | philip.jenvey | 2009-09-28 21:32:44 -0700 (Mon, 28 Sep 2009) | 4 lines

  #6990: clear threading.local's key only after its thread state is removed:
  fixes local subclasses leaving old state around after a ref cycle GC which
  could be recycled by new locals
........
diff --git a/Modules/threadmodule.c b/Modules/threadmodule.c
index a87ddb3..ca47ebf 100644
--- a/Modules/threadmodule.c
+++ b/Modules/threadmodule.c
@@ -227,7 +227,6 @@
 static int
 local_clear(localobject *self)
 {
-	Py_CLEAR(self->key);
 	Py_CLEAR(self->args);
 	Py_CLEAR(self->kw);
 	Py_CLEAR(self->dict);
@@ -249,6 +248,7 @@
 				PyDict_DelItem(tstate->dict, self->key);
 	}
 
+	Py_XDECREF(self->key);
 	local_clear(self);
 	Py_TYPE(self)->tp_free((PyObject*)self);
 }