summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2014-10-01 19:23:46 +0200
committerGravatar Martin Szulecki2014-10-01 19:23:46 +0200
commit9665773d8ae5eaf1679574b15dab133ab9d0de72 (patch)
tree0b59b3f86e9e6d62f4606daae58c59f9fa2d3eba /src
parent9732d275d00bb1200d2b6180d94814a1a7fb7696 (diff)
downloadlibimobiledevice-9665773d8ae5eaf1679574b15dab133ab9d0de72.tar.gz
libimobiledevice-9665773d8ae5eaf1679574b15dab133ab9d0de72.tar.bz2
idevice: Fix several memory leaks on deinitialization of OpenSSL
Diffstat (limited to 'src')
-rw-r--r--src/idevice.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/idevice.c b/src/idevice.c
index 3b903c0..8cacf4c 100644
--- a/src/idevice.c
+++ b/src/idevice.c
@@ -35,6 +35,7 @@
#include <usbmuxd.h>
#ifdef HAVE_OPENSSL
+#include <openssl/err.h>
#include <openssl/ssl.h>
#else
#include <gnutls/gnutls.h>
@@ -83,14 +84,19 @@ static void internal_idevice_deinit(void)
{
#ifdef HAVE_OPENSSL
int i;
- if (!mutex_buf)
- return;
- CRYPTO_set_id_callback(NULL);
- CRYPTO_set_locking_callback(NULL);
- for (i = 0; i < CRYPTO_num_locks(); i++)
- mutex_destroy(&mutex_buf[i]);
- free(mutex_buf);
- mutex_buf = NULL;
+ if (mutex_buf) {
+ CRYPTO_set_id_callback(NULL);
+ CRYPTO_set_locking_callback(NULL);
+ for (i = 0; i < CRYPTO_num_locks(); i++)
+ mutex_destroy(&mutex_buf[i]);
+ free(mutex_buf);
+ mutex_buf = NULL;
+ }
+
+ EVP_cleanup();
+ CRYPTO_cleanup_all_ex_data();
+ sk_SSL_COMP_free(SSL_COMP_get_compression_methods());
+ ERR_remove_thread_state(NULL);
#else
gnutls_global_deinit();
#endif
@@ -710,6 +716,8 @@ idevice_error_t idevice_connection_enable_ssl(idevice_connection_t connection)
ret = IDEVICE_E_SUCCESS;
debug_info("SSL mode enabled, cipher: %s", SSL_get_cipher(ssl));
}
+ /* required for proper multi-thread clean up to prevent leaks */
+ ERR_remove_thread_state(NULL);
#else
ssl_data_t ssl_data_loc = (ssl_data_t)malloc(sizeof(struct ssl_data_private));