summaryrefslogtreecommitdiffstats
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
parent9732d275d00bb1200d2b6180d94814a1a7fb7696 (diff)
downloadlibimobiledevice-9665773d8ae5eaf1679574b15dab133ab9d0de72.tar.gz
libimobiledevice-9665773d8ae5eaf1679574b15dab133ab9d0de72.tar.bz2
idevice: Fix several memory leaks on deinitialization of OpenSSL
-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 @@
35 35
36#include <usbmuxd.h> 36#include <usbmuxd.h>
37#ifdef HAVE_OPENSSL 37#ifdef HAVE_OPENSSL
38#include <openssl/err.h>
38#include <openssl/ssl.h> 39#include <openssl/ssl.h>
39#else 40#else
40#include <gnutls/gnutls.h> 41#include <gnutls/gnutls.h>
@@ -83,14 +84,19 @@ static void internal_idevice_deinit(void)
83{ 84{
84#ifdef HAVE_OPENSSL 85#ifdef HAVE_OPENSSL
85 int i; 86 int i;
86 if (!mutex_buf) 87 if (mutex_buf) {
87 return; 88 CRYPTO_set_id_callback(NULL);
88 CRYPTO_set_id_callback(NULL); 89 CRYPTO_set_locking_callback(NULL);
89 CRYPTO_set_locking_callback(NULL); 90 for (i = 0; i < CRYPTO_num_locks(); i++)
90 for (i = 0; i < CRYPTO_num_locks(); i++) 91 mutex_destroy(&mutex_buf[i]);
91 mutex_destroy(&mutex_buf[i]); 92 free(mutex_buf);
92 free(mutex_buf); 93 mutex_buf = NULL;
93 mutex_buf = NULL; 94 }
95
96 EVP_cleanup();
97 CRYPTO_cleanup_all_ex_data();
98 sk_SSL_COMP_free(SSL_COMP_get_compression_methods());
99 ERR_remove_thread_state(NULL);
94#else 100#else
95 gnutls_global_deinit(); 101 gnutls_global_deinit();
96#endif 102#endif
@@ -710,6 +716,8 @@ idevice_error_t idevice_connection_enable_ssl(idevice_connection_t connection)
710 ret = IDEVICE_E_SUCCESS; 716 ret = IDEVICE_E_SUCCESS;
711 debug_info("SSL mode enabled, cipher: %s", SSL_get_cipher(ssl)); 717 debug_info("SSL mode enabled, cipher: %s", SSL_get_cipher(ssl));
712 } 718 }
719 /* required for proper multi-thread clean up to prevent leaks */
720 ERR_remove_thread_state(NULL);
713#else 721#else
714 ssl_data_t ssl_data_loc = (ssl_data_t)malloc(sizeof(struct ssl_data_private)); 722 ssl_data_t ssl_data_loc = (ssl_data_t)malloc(sizeof(struct ssl_data_private));
715 723