diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-03-23 06:20:50 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-03-23 06:20:50 +0000 |
commit | 905c16846aa52841581204d53d0bfbdd5252a2ff (patch) | |
tree | 0c4afd2d180cfa80e21770af36de1a15bf4056d1 | |
parent | b7ce4d1d3d59ec41674d7251d880729175b1a87c (diff) | |
download | tor-905c16846aa52841581204d53d0bfbdd5252a2ff.tar tor-905c16846aa52841581204d53d0bfbdd5252a2ff.tar.gz |
Fix a few more instances of memory not freed on exit (found by weasel).
svn:r3830
-rw-r--r-- | src/common/crypto.c | 19 | ||||
-rw-r--r-- | src/or/dirserv.c | 4 |
2 files changed, 21 insertions, 2 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index f851903c4..c88be4b82 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -79,6 +79,11 @@ const char crypto_c_id[] = "$Id$"; /** Macro: is k a valid RSA private key? */ #define PRIVATE_KEY_OK(k) ((k) && (k)->key && (k)->key->p) +#ifdef TOR_IS_MULTITHREADED +static tor_mutex_t **_openssl_mutexes = NULL; +static int _n_openssl_mutexes = -1; +#endif + struct crypto_pk_env_t { int refs; /* reference counting so we don't have to copy keys */ @@ -170,6 +175,16 @@ int crypto_global_init() int crypto_global_cleanup() { ERR_free_strings(); +#ifdef TOR_IS_MULTITHREADED + if (_n_openssl_mutexes) { + int i; + for (i=0;i<_n_openssl_mutexes;++i) { + tor_mutex_free(_openssl_mutexes[i]); + } + tor_free(_openssl_mutexes); + _n_openssl_mutexes = 0; + } +#endif return 0; } @@ -1631,7 +1646,6 @@ secret_to_key(char *key_out, size_t key_out_len, const char *secret, } #ifdef TOR_IS_MULTITHREADED -static tor_mutex_t **_openssl_mutexes = NULL; static void _openssl_locking_cb(int mode, int n, const char *file, int line) { @@ -1644,8 +1658,9 @@ static int setup_openssl_threading(void) { int i; int n = CRYPTO_num_locks(); + _n_openssl_mutexes = n; _openssl_mutexes = tor_malloc(n*sizeof(tor_mutex_t *)); - for (i=0; i <n; ++i) + for (i=0; i < n; ++i) _openssl_mutexes[i] = tor_mutex_new(); CRYPTO_set_locking_callback(_openssl_locking_cb); CRYPTO_set_id_callback(tor_get_thread_id); diff --git a/src/or/dirserv.c b/src/or/dirserv.c index 3df96e14f..5f6b314bb 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -990,6 +990,10 @@ dirserv_free_all(void) tor_free(the_directory_z); the_directory_len = 0; the_directory_z_len = 0; + tor_free(the_runningrouters); + tor_free(the_runningrouters_z); + the_runningrouters_len = 0; + the_runningrouters_z_len = 0; tor_free(cached_directory.dir); tor_free(cached_directory.dir_z); tor_free(cached_runningrouters.dir); |