summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Menšík <pemensik@redhat.com>2021-04-14 21:08:31 +0100
committerSimon Kelley <simon@thekelleys.org.uk>2021-04-14 21:08:31 +0100
commit10d8b5f001a34ff46b3a72575f3af64b065f8637 (patch)
tree8c2c31dd6fff11ccb5d32e63ed883d5b822dc5f9
parentffd3ceb856eb3e1ff923cae95a2ddb889beab7c1 (diff)
downloaddnsmasq-10d8b5f001a34ff46b3a72575f3af64b065f8637.tar.gz
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.
-rw-r--r--src/option.c42
1 files 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;