Free more memory in cleanup functions.

The extra free in ex_data_impl.c is fixing a mistake: when calling
|CRYPTO_cleanup_all_ex_data| the |EX_CLASS_ITEM| itself wouldn't be
freed.

The change in err_impl.c is to free the thread-id hash also. This allows
programs to free absolutely all memory allocated by BoringSSL, which
allows fuzz testing to find any memory leaks.

Change-Id: I1e518adf2b3e0efa7d7f00f7ab4e65e1dc70161e
Reviewed-on: https://boringssl-review.googlesource.com/2670
Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
Adam Langley 2014-12-19 12:24:59 -08:00
parent a307dfd29f
commit 2bca0988a4
3 changed files with 9 additions and 2 deletions

View File

@ -293,6 +293,10 @@ static void err_shutdown(void) {
lh_ERR_STRING_DATA_free(error_hash);
error_hash = NULL;
}
if (state_hash) {
lh_ERR_STATE_free(state_hash);
state_hash = NULL;
}
CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
}

View File

@ -167,6 +167,7 @@ static void data_funcs_free(CRYPTO_EX_DATA_FUNCS *funcs) {
* structures. */
static void class_free(EX_CLASS_ITEM *item) {
sk_CRYPTO_EX_DATA_FUNCS_pop_free(item->meth, data_funcs_free);
OPENSSL_free(item);
}
static LHASH_OF(EX_CLASS_ITEM) *get_classes(void) {

View File

@ -148,8 +148,10 @@ extern "C" {
* human-readable strings. */
OPENSSL_EXPORT void ERR_load_crypto_strings(void);
/* ERR_free_strings frees any internal error values that have been loaded. This
* should only be called at process shutdown. */
/* ERR_free_strings frees any memory retained by the error system, expect for
* per-thread structures which are assumed to have already been freed with
* |ERR_remove_thread_state|. This should only be called at process
* shutdown. */
OPENSSL_EXPORT void ERR_free_strings(void);