From 10d8b5f001a34ff46b3a72575f3af64b065f8637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= Date: Wed, 14 Apr 2021 21:08:31 +0100 Subject: [PATCH] Reduce code duplication, reuse existing functions dhcp_config_free and dhcp_opt_free already implement the same algorithm. Reuse them. Adds forgotten hostname cleanup to config free. --- src/option.c | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/src/option.c b/src/option.c index e8926a4..23cf058 100644 --- a/src/option.c +++ b/src/option.c @@ -1067,6 +1067,8 @@ static void dhcp_config_free(struct dhcp_config *config) if (config->flags & CONFIG_CLID) free(config->clid); + if (config->flags & CONFIG_NAME) + free(config->hostname); #ifdef HAVE_DHCP6 if (config->flags & CONFIG_ADDR6) @@ -5002,30 +5004,8 @@ static void clear_dynamic_conf(void) if (configs->flags & CONFIG_BANK) { - struct hwaddr_config *mac, *tmp; - struct dhcp_netid_list *list, *tmplist; - - for (mac = configs->hwaddr; mac; mac = tmp) - { - tmp = mac->next; - free(mac); - } - - if (configs->flags & CONFIG_CLID) - free(configs->clid); - - for (list = configs->netid; list; list = tmplist) - { - free(list->list); - tmplist = list->next; - free(list); - } - - if (configs->flags & CONFIG_NAME) - free(configs->hostname); - - *up = configs->next; - free(configs); + *up = cp; + dhcp_config_free(configs); } else up = &configs->next; @@ -5035,7 +5015,6 @@ static void clear_dynamic_conf(void) static void clear_dynamic_opt(void) { struct dhcp_opt *opts, *cp, **up; - struct dhcp_netid *id, *next; for (up = &daemon->dhcp_opts, opts = daemon->dhcp_opts; opts; opts = cp) { @@ -5043,17 +5022,8 @@ static void clear_dynamic_opt(void) if (opts->flags & DHOPT_BANK) { - if ((opts->flags & DHOPT_VENDOR)) - free(opts->u.vendor_class); - free(opts->val); - for (id = opts->netid; id; id = next) - { - next = id->next; - free(id->net); - free(id); - } - *up = opts->next; - free(opts); + *up = cp; + dhcp_opt_free(opts); } else up = &opts->next;