Commit 344b4ead60da5fc3514f602a8e1a6af15173cc31

Edward Thomson 2017-12-01T11:27:15

Merge pull request #4427 from pks-t/pks/openssl-threadid openssl: fix thread-safety on non-glibc POSIX systems

diff --git a/src/streams/openssl.c b/src/streams/openssl.c
index 56164bf..2b24600 100644
--- a/src/streams/openssl.c
+++ b/src/streams/openssl.c
@@ -150,11 +150,20 @@ int git_openssl_stream_global_init(void)
 	return 0;
 }
 
+#if defined(GIT_THREADS)
+static void threadid_cb(CRYPTO_THREADID *threadid)
+{
+    CRYPTO_THREADID_set_numeric(threadid, git_thread_currentid());
+}
+#endif
+
 int git_openssl_set_locking(void)
 {
 #if defined(GIT_THREADS) && OPENSSL_VERSION_NUMBER < 0x10100000L
 	int num_locks, i;
 
+	CRYPTO_THREADID_set_callback(threadid_cb);
+
 	num_locks = CRYPTO_num_locks();
 	openssl_locks = git__calloc(num_locks, sizeof(git_mutex));
 	GITERR_CHECK_ALLOC(openssl_locks);