From f635812ccc9b2eb63f5bc2b494d7fdae9c9e1ef3 Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Wed, 26 Apr 2017 11:36:54 +0200 Subject: Don't use ERR_remove_thread_state() with OpenSSL 1.1.0 It's deprecated and causes compile-time warnings. We don't want to fallback to ERR_remove_state() either as it's similarly deprecated. This commit adds a helper functions to hide the #ifdef mess between the various openssl versions. Signed-off-by: Christophe Fergeau --- src/idevice.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/idevice.c b/src/idevice.c index d1f13cb..1c43269 100644 --- a/src/idevice.c +++ b/src/idevice.c @@ -37,10 +37,7 @@ #ifdef HAVE_OPENSSL #include #include -#if OPENSSL_VERSION_NUMBER >= 0x10000001L -/* since OpenSSL 1.0.0-beta1 */ -#define HAVE_ERR_REMOVE_THREAD_STATE 1 -#endif + #else #include #endif @@ -59,6 +56,19 @@ static void SSL_COMP_free_compression_methods(void) } #endif +static void openssl_remove_thread_state(void) +{ +/* ERR_remove_thread_state() is available since OpenSSL 1.0.0-beta1, but + * deprecated in OpenSSL 1.1.0 */ +#if OPENSSL_VERSION_NUMBER < 0x10100000L +#if OPENSSL_VERSION_NUMBER >= 0x10000001L + ERR_remove_thread_state(NULL); +#else + ERR_remove_state(0); +#endif +#endif +} + static mutex_t *mutex_buf = NULL; static void locking_function(int mode, int n, const char* file, int line) { @@ -109,11 +119,7 @@ static void internal_idevice_deinit(void) EVP_cleanup(); CRYPTO_cleanup_all_ex_data(); SSL_COMP_free_compression_methods(); -#ifdef HAVE_ERR_REMOVE_THREAD_STATE - ERR_remove_thread_state(NULL); -#else - ERR_remove_state(0); -#endif + openssl_remove_thread_state(); #else gnutls_global_deinit(); #endif @@ -764,11 +770,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_enable_ssl(idevice_conne debug_info("SSL mode enabled, cipher: %s", SSL_get_cipher(ssl)); } /* required for proper multi-thread clean up to prevent leaks */ -#ifdef HAVE_ERR_REMOVE_THREAD_STATE - ERR_remove_thread_state(NULL); -#else - ERR_remove_state(0); -#endif + openssl_remove_thread_state(); #else ssl_data_t ssl_data_loc = (ssl_data_t)malloc(sizeof(struct ssl_data_private)); -- cgit v1.1-32-gdbae