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 <cfergeau@redhat.com>
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 <openssl/err.h>
#include <openssl/ssl.h>
-#if OPENSSL_VERSION_NUMBER >= 0x10000001L
-/* since OpenSSL 1.0.0-beta1 */
-#define HAVE_ERR_REMOVE_THREAD_STATE 1
-#endif
+
#else
#include <gnutls/gnutls.h>
#endif
@@ -59,6 +56,19 @@
}
#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 @@
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 @@
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));