]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Explicitly freeing the dictionary really isn't required... something else must be...
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 6 Apr 2021 16:20:59 +0000 (17:20 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 6 Apr 2021 16:20:59 +0000 (17:20 +0100)
src/bin/radiusd.c
src/lib/tls/base-h
src/lib/tls/base.c
src/lib/util/dict_util.c

index d7bc0f161beac14eb6d2a93f97b816431090bc87..6231c78b80bc2535f08eedf26d722218dcaf0794 100644 (file)
@@ -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
         */
index a94de33f86cf7a0d87ba7e27530d87d2a1764bc3..5aabd45b74ee9f07fdf8aaca33ea921aa84f6b50 100644 (file)
@@ -429,8 +429,6 @@ void                fr_openssl_free(void);
 
 int            fr_tls_dict_init(void);
 
-void           fr_tls_dict_free(void);
-
 /*
  *     tls/log.c
  */
index 51bc3b7da0a806041822252ce459832e00b7b459..6acfdc66a922f2db627ac70214d3ecef8496503d 100644 (file)
@@ -39,7 +39,6 @@ USES_APPLE_DEPRECATED_API     /* OpenSSL API has been deprecated by Apple */
 #include <freeradius-devel/util/debug.h>
 
 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 */
index 8a36b854e78d3797ca6f182849daf534d67ee14a..6024883fafe751643b5a67096ebee6d7b8ccfc45 100644 (file)
@@ -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;
        }
 }