Skip to content

Commit 344b4ea

Browse files
authored
Merge pull request libgit2#4427 from pks-t/pks/openssl-threadid
openssl: fix thread-safety on non-glibc POSIX systems
2 parents 494a2f2 + 2d2e70f commit 344b4ea

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/streams/openssl.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,20 @@ int git_openssl_stream_global_init(void)
150150
return 0;
151151
}
152152

153+
#if defined(GIT_THREADS)
154+
static void threadid_cb(CRYPTO_THREADID *threadid)
155+
{
156+
CRYPTO_THREADID_set_numeric(threadid, git_thread_currentid());
157+
}
158+
#endif
159+
153160
int git_openssl_set_locking(void)
154161
{
155162
#if defined(GIT_THREADS) && OPENSSL_VERSION_NUMBER < 0x10100000L
156163
int num_locks, i;
157164

165+
CRYPTO_THREADID_set_callback(threadid_cb);
166+
158167
num_locks = CRYPTO_num_locks();
159168
openssl_locks = git__calloc(num_locks, sizeof(git_mutex));
160169
GITERR_CHECK_ALLOC(openssl_locks);

0 commit comments

Comments
 (0)