Fix the thread-related segfault
diff --git a/ChangeLog b/ChangeLog
index 6e70a4d..4b2ffb9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,13 @@
 2009-04-01  Jean-Paul Calderone  <exarkun@twistedmatrix.com>
+            Samuele Pedroni  <pedronis@openend.se>
+
+	* src/util.h: Delete the TLS key before trying to set a new value
+	  for it in case the current thread identifier is a recycled one (if
+	  it is recycled, the key won't be set because there is already a
+	  value from the previous thread to have this identifier and to use
+	  the pyOpenSSL API).
+
+2009-04-01  Jean-Paul Calderone  <exarkun@twistedmatrix.com>
 
 	* src/crypto/crypto.c: Add FILETYPE_TEXT for dumping keys and
 	  certificates and certificate signature requests to a text format.
diff --git a/src/util.h b/src/util.h
index b95e75b..1774956 100644
--- a/src/util.h
+++ b/src/util.h
@@ -37,6 +37,7 @@
  * some Python.
  */
 #  define MY_BEGIN_ALLOW_THREADS(ignored)                               \
+    PyThread_delete_key_value(_pyOpenSSL_tstate_key);			\
     PyThread_set_key_value(_pyOpenSSL_tstate_key, PyEval_SaveThread());
 
 /*