From: Arran Cudbard-Bell Date: Tue, 6 Apr 2021 16:20:59 +0000 (+0100) Subject: Explicitly freeing the dictionary really isn't required... something else must be... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=844ee9d332017220a176e6496c90856e5084abc4;p=thirdparty%2Ffreeradius-server.git Explicitly freeing the dictionary really isn't required... something else must be happening --- diff --git a/src/bin/radiusd.c b/src/bin/radiusd.c index d7bc0f161b..6231c78b80 100644 --- a/src/bin/radiusd.c +++ b/src/bin/radiusd.c @@ -700,7 +700,7 @@ int main(int argc, char *argv[]) /* * Initialise the interpreter, registering operations. */ - if (unlang_init_global() < 0) return -1; + if (unlang_init_global() < 0) EXIT_WITH_FAILURE; if (server_init(config->root_cs) < 0) EXIT_WITH_FAILURE; @@ -1006,13 +1006,6 @@ cleanup: */ if (dl_modules) talloc_free(dl_modules); -#ifdef HAVE_OPENSSL_CRYPTO_H - /* - * Make sure we clean up the TLS dictionary... - */ - fr_tls_dict_free(); -#endif - /* * Cleanup everything else */ diff --git a/src/lib/tls/base-h b/src/lib/tls/base-h index a94de33f86..5aabd45b74 100644 --- a/src/lib/tls/base-h +++ b/src/lib/tls/base-h @@ -429,8 +429,6 @@ void fr_openssl_free(void); int fr_tls_dict_init(void); -void fr_tls_dict_free(void); - /* * tls/log.c */ diff --git a/src/lib/tls/base.c b/src/lib/tls/base.c index 51bc3b7da0..6acfdc66a9 100644 --- a/src/lib/tls/base.c +++ b/src/lib/tls/base.c @@ -39,7 +39,6 @@ USES_APPLE_DEPRECATED_API /* OpenSSL API has been deprecated by Apple */ #include static uint32_t instance_count = 0; -static uint32_t dict_ref_count = 0; /** The context which holds any memory OpenSSL allocates * @@ -482,7 +481,7 @@ void fr_openssl_free(void) TALLOC_FREE(global_mutexes); - fr_tls_dict_free(); + fr_dict_autofree(tls_dict); } #else /** Free any memory alloced by libssl @@ -500,7 +499,7 @@ void fr_openssl_free(void) OPENSSL_cleanup(); - fr_tls_dict_free(); + fr_dict_autofree(tls_dict); } #endif @@ -566,22 +565,15 @@ int fr_openssl_init(void) /** Load dictionary attributes * + * This is a separate function because of ordering issues. + * OpenSSL may need to be initialised before anything else + * including the dictionary loader. + * + * fr_openssl_free will unload both the dictionary and the + * OpenSSL library. */ int fr_tls_dict_init(void) { - /* - * Needs to be tracked separately in case - * this is called before the TLS library - * is initialised. - * - * fr_dict_autofree will only decrement the - * dict ref count once. - */ - if (dict_ref_count > 0) { - dict_ref_count++; - return 0; - } - if (fr_dict_autoload(tls_dict) < 0) { PERROR("Failed initialising protocol library"); fr_openssl_free(); @@ -593,16 +585,6 @@ int fr_tls_dict_init(void) fr_openssl_free(); return -1; } - - dict_ref_count++; - return 0; } - -void fr_tls_dict_free(void) -{ - if (--dict_ref_count > 0) return; - - fr_dict_autofree(tls_dict); -} #endif /* WITH_TLS */ diff --git a/src/lib/util/dict_util.c b/src/lib/util/dict_util.c index 8a36b854e7..6024883faf 100644 --- a/src/lib/util/dict_util.c +++ b/src/lib/util/dict_util.c @@ -3024,7 +3024,7 @@ void fr_dict_autofree(fr_dict_autoload_t const *to_free) memcpy(&dict, &p->out, sizeof(dict)); /* const issues */ if (!*dict) continue; - fr_dict_free(dict); + if (fr_dict_free(dict) == 0) *dict = NULL; } }