Patch #751916: Check for signals, fix some refcounting errors.
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 8fe0428..16edadd 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -245,14 +245,17 @@
 		ret = SSL_connect(self->ssl);
 		err = SSL_get_error(self->ssl, ret);
 		Py_END_ALLOW_THREADS
+		if(PyErr_CheckSignals()) {
+                        goto fail;
+		}
 		if (err == SSL_ERROR_WANT_READ) {
 			timedout = wait_for_timeout(Sock, 0);
 		} else if (err == SSL_ERROR_WANT_WRITE) {
 			timedout = wait_for_timeout(Sock, 1);
 		}
 		if (timedout) {
-			PyErr_SetString(PySSLErrorObject, "The connect operation timed out");
-			return NULL;
+			errstr = "The connect operation timed out";
+			goto fail;
 		}
 	} while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);
 	if (ret <= 0) {
@@ -387,6 +390,9 @@
 		len = SSL_write(self->ssl, data, len);
 		err = SSL_get_error(self->ssl, len);
 		Py_END_ALLOW_THREADS
+		if(PyErr_CheckSignals()) {
+			return NULL;
+		}
 		if (err == SSL_ERROR_WANT_READ) {
 			timedout = wait_for_timeout(self->Socket, 0);
 		} else if (err == SSL_ERROR_WANT_WRITE) {
@@ -434,6 +440,10 @@
 		count = SSL_read(self->ssl, PyString_AsString(buf), len);
 		err = SSL_get_error(self->ssl, count);
 		Py_END_ALLOW_THREADS
+		if(PyErr_CheckSignals()) {
+			Py_DECREF(buf);
+			return NULL;
+		}
 		if (err == SSL_ERROR_WANT_READ) {
 			timedout = wait_for_timeout(self->Socket, 0);
 		} else if (err == SSL_ERROR_WANT_WRITE) {
@@ -441,6 +451,7 @@
 		}
 		if (timedout) {
 			PyErr_SetString(PySSLErrorObject, "The read operation timed out");
+			Py_DECREF(buf);
 			return NULL;
 		}
 	} while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);