aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlice Mitchell <ajmitchell@redhat.com>2021-04-12 14:23:17 -0400
committerSteve Dickson <steved@redhat.com>2021-05-06 12:45:47 -0400
commit964f4861605785c68c1ccdbf978f95739505771a (patch)
treee9d776ef42b3777a12970ff3f1cfb2abf41d77df
parent8219bdb00cc749e17e8ed782eb264bd93f7b9a35 (diff)
downloadnfs-utils-964f4861605785c68c1ccdbf978f95739505771a.tar.gz
nfs-utils: Factor out common structure cleanup calls
Signed-off-by: Alice Mitchell <ajmitchell@redhat.com> Signed-off-by: Steve Dickson <steved@redhat.com>
-rw-r--r--support/nfs/conffile.c84
1 files changed, 41 insertions, 43 deletions
diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c
index a4ea0676..1e15e7d5 100644
--- a/support/nfs/conffile.c
+++ b/support/nfs/conffile.c
@@ -133,6 +133,39 @@ conf_hash(const char *s)
}
/*
+ * free all the component parts of a conf_binding struct
+ */
+static void free_confbind(struct conf_binding *cb)
+{
+ if (!cb)
+ return;
+ if (cb->section)
+ free(cb->section);
+ if (cb->arg)
+ free(cb->arg);
+ if (cb->tag)
+ free(cb->tag);
+ if (cb->value)
+ free(cb->value);
+ free(cb);
+}
+
+static void free_conftrans(struct conf_trans *ct)
+{
+ if (!ct)
+ return;
+ if (ct->section)
+ free(ct->section);
+ if (ct->arg)
+ free(ct->arg);
+ if (ct->tag)
+ free(ct->tag);
+ if (ct->value)
+ free(ct->value);
+ free(ct);
+}
+
+/*
* Insert a tag-value combination from LINE (the equal sign is at POS)
*/
static int
@@ -147,11 +180,7 @@ conf_remove_now(const char *section, const char *tag)
&& strcasecmp(cb->tag, tag) == 0) {
LIST_REMOVE(cb, link);
xlog(LOG_INFO,"[%s]:%s->%s removed", section, tag, cb->value);
- free(cb->section);
- free(cb->arg);
- free(cb->tag);
- free(cb->value);
- free(cb);
+ free_confbind(cb);
return 0;
}
}
@@ -171,11 +200,7 @@ conf_remove_section_now(const char *section)
unseen = 0;
LIST_REMOVE(cb, link);
xlog(LOG_INFO, "[%s]:%s->%s removed", section, cb->tag, cb->value);
- free(cb->section);
- free(cb->arg);
- free(cb->tag);
- free(cb->value);
- free(cb);
+ free_confbind(cb);
}
}
return unseen;
@@ -571,11 +596,7 @@ static void conf_free_bindings(void)
for (; cb; cb = next) {
next = LIST_NEXT(cb, link);
LIST_REMOVE(cb, link);
- free(cb->section);
- free(cb->arg);
- free(cb->tag);
- free(cb->value);
- free(cb);
+ free_confbind(cb);
}
LIST_INIT(&conf_bindings[i]);
}
@@ -774,11 +795,7 @@ conf_cleanup(void)
for (node = TAILQ_FIRST(&conf_trans_queue); node; node = next) {
next = TAILQ_NEXT(node, link);
TAILQ_REMOVE (&conf_trans_queue, node, link);
- if (node->section) free(node->section);
- if (node->arg) free(node->arg);
- if (node->tag) free(node->tag);
- if (node->value) free(node->value);
- free (node);
+ free_conftrans(node);
}
TAILQ_INIT(&conf_trans_queue);
}
@@ -1144,14 +1161,7 @@ conf_set(int transaction, const char *section, const char *arg,
return 0;
fail:
- if (node->tag)
- free(node->tag);
- if (node->arg)
- free(node->arg);
- if (node->section)
- free(node->section);
- if (node)
- free(node);
+ free_conftrans(node);
return 1;
}
@@ -1177,10 +1187,7 @@ conf_remove(int transaction, const char *section, const char *tag)
return 0;
fail:
- if (node && node->section)
- free (node->section);
- if (node)
- free (node);
+ free_conftrans(node);
return 1;
}
@@ -1201,8 +1208,7 @@ conf_remove_section(int transaction, const char *section)
return 0;
fail:
- if (node)
- free(node);
+ free_conftrans(node);
return 1;
}
@@ -1233,15 +1239,7 @@ conf_end(int transaction, int commit)
}
}
TAILQ_REMOVE (&conf_trans_queue, node, link);
- if (node->section)
- free(node->section);
- if (node->arg)
- free(node->arg);
- if (node->tag)
- free(node->tag);
- if (node->value)
- free(node->value);
- free (node);
+ free_conftrans(node);
}
}
return 0;