]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Move packet global free to the atexit handlers
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 15 May 2024 01:59:50 +0000 (19:59 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 15 May 2024 01:59:50 +0000 (19:59 -0600)
src/bin/dhcpclient.c
src/bin/radclient-ng.c
src/bin/radclient.c
src/lib/server/base.c
src/lib/server/packet.c
src/lib/server/packet.h

index a892c213f2664bd091a593f3dec5d7fdf8ba035a..50e7687664c5ba075280a8ac7d8b7248f9bd6e86 100644 (file)
@@ -738,8 +738,6 @@ int main(int argc, char **argv)
 
        fr_dhcpv4_global_free();
 
-       packet_global_free();
-
        if (fr_dict_autofree(dhcpclient_dict) < 0) {
                fr_perror("dhcpclient");
                ret = -1;
index 1bc5a82c626d709dbbb06f3ee42418cdec89a842..60ad50dc164b94b1ac75058f604f24fc362f853a 100644 (file)
@@ -1739,8 +1739,6 @@ int main(int argc, char **argv)
 
        fr_radius_global_free();
 
-       packet_global_free();
-
        if (fr_dict_autofree(radclient_dict) < 0) {
                fr_perror("radclient");
                ret = EXIT_FAILURE;
index 84408dbf4971950a3ef0025532369442850dd2f2..ee12c0a57a5906ccae7d8e702ef418147c64786b 100644 (file)
@@ -2065,8 +2065,6 @@ int main(int argc, char **argv)
 
        fr_radius_global_free();
 
-       packet_global_free();
-
        if (fr_dict_autofree(radclient_dict) < 0) {
                fr_perror("radclient");
                ret = EXIT_FAILURE;
index e680d4c5175b3901cdb5201a2074ff00897c2fce..283934df3b3dfc67592eda3e7023ea5e20286d28 100644 (file)
@@ -110,11 +110,6 @@ int server_init(CONF_SECTION *cs)
  */
 void server_free(void)
 {
-       /*
-        *      Free any resources used by 'Net.' packet
-        */
-       packet_global_free();
-
        /*
         *      Free xlat instance data, and call any detach methods
         */
index 2882adc211306f4b45c705eac0f54f2331a68eb7..4dc2b7d7b70550d617c7a00f2286c5e2d9a7a514 100644 (file)
  *
  * @copyright 2023 Network RADIUS SAS (legal@networkradius.com)
  */
+
 RCSID("$Id$")
 
-#include <freeradius-devel/server/packet.h>
+#include <freeradius-devel/util/atexit.h>
 #include <freeradius-devel/util/pair_legacy.h>
 
+#include <freeradius-devel/server/packet.h>
+
 static fr_dict_t const *dict_freeradius;
 
 extern fr_dict_autoload_t util_packet_dict[];
@@ -153,14 +156,14 @@ void fr_packet_pairs_to_packet(fr_packet_t *packet, fr_pair_list_t const *list)
        }
 }
 
-/** Initialises the Net. packet attributes.
- *
- * @note Call packet_global_free() when the server is done to avoid leaks.
- * @return
- *     - 0 on success.
- *     - -1 on failure.
- */
-int packet_global_init(void)
+static int _packet_global_free(UNUSED void *uctx)
+{
+       fr_dict_autofree(util_packet_dict);
+
+       return 0;
+}
+
+static int _packet_global_init(UNUSED void *uctx)
 {
        if (fr_dict_autoload(util_packet_dict) < 0) {
        error:
@@ -173,7 +176,17 @@ int packet_global_init(void)
        return 0;
 }
 
-void packet_global_free(void)
+/** Initialises the Net. packet attributes.
+ *
+ * @return
+ *     - 0 on success.
+ *     - -1 on failure.
+ */
+int packet_global_init(void)
 {
-       fr_dict_autofree(util_packet_dict);
+       int ret;
+
+       fr_atexit_global_once_ret(&ret, _packet_global_init, _packet_global_free, NULL);
+
+       return ret;
 }
index 50bd51c5228e98a238e6b83705505d45ad80421b..3ef57fdc37ea8872988e84d6d402bbea624d49c1 100644 (file)
@@ -34,7 +34,6 @@ int fr_packet_pairs_from_packet(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_packet
 void fr_packet_pairs_to_packet(fr_packet_t *packet, fr_pair_list_t const *list) CC_HINT(nonnull);
 
 int packet_global_init(void);
-void packet_global_free(void);
 
 #ifdef __cplusplus
 }