From c324f1783e2d0978012d58f25349d50bb35e63c3 Mon Sep 17 00:00:00 2001 From: Piotr Sikora Date: Mon, 16 Nov 2015 23:56:55 -0800 Subject: [PATCH] Make sure pthread_once() succeeds. It can fail on FreeBSD when library is not linked against either threading library and results in init routine not being executed at all, leading to errors in other parts of the code. Change-Id: I1063f6940e381e6470593c063fbfecf3f47991cd Signed-off-by: Piotr Sikora Reviewed-on: https://boringssl-review.googlesource.com/6522 Reviewed-by: Adam Langley --- crypto/thread_pthread.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crypto/thread_pthread.c b/crypto/thread_pthread.c index 59c4b8d1..68aaab5b 100644 --- a/crypto/thread_pthread.c +++ b/crypto/thread_pthread.c @@ -17,6 +17,7 @@ #if !defined(OPENSSL_WINDOWS) && !defined(OPENSSL_NO_THREADS) #include +#include #include #include @@ -74,7 +75,11 @@ void CRYPTO_STATIC_MUTEX_unlock(struct CRYPTO_STATIC_MUTEX *lock) { } void CRYPTO_once(CRYPTO_once_t *once, void (*init)(void)) { - pthread_once(once, init); + if (pthread_once(once, init) != 0) { + fprintf(stderr, + "pthread_once failed. Did you link against a threading library?\n"); + abort(); + } } static pthread_mutex_t g_destructors_lock = PTHREAD_MUTEX_INITIALIZER;