void cf_section_free(CONF_SECTION **cp);
int cf_item_parse(const CONF_SECTION *cs, const char *name,
int type, void *data, const char *dflt);
-int cf_section_parse(const CONF_SECTION *, void *base, const CONF_PARSER *variables);
+int cf_section_parse(const CONF_SECTION *, void *base,
+ const CONF_PARSER *variables);
+/*
+ * Free strings we've parsed into a structure.
+ */
+void cf_section_parse_free_strings(void *base,
+ const CONF_PARSER *variables);
CONF_SECTION *conf_read(const char *fromfile, int fromline,
const char *conffile, CONF_SECTION *parent);
return 0;
}
+
+/*
+ * Free strings we've parsed into data structures.
+ */
+void cf_section_parse_free_strings(void *base, const CONF_PARSER *variables)
+{
+ int i;
+
+ if (!variables) return;
+
+ /*
+ * Free up dynamically allocated string pointers.
+ */
+ for (i = 0; variables[i].name != NULL; i++) {
+ char **p;
+
+ if (variables[i].type != PW_TYPE_STRING_PTR) {
+ continue;
+ }
+
+ /*
+ * Prefer the data, if it's there.
+ * Else use the base + offset.
+ */
+ if (variables[i].data) {
+ p = (char **) &(variables[i].data);
+ } else {
+ p = (char **) (((char *)base) + variables[i].offset);
+ }
+ free(*p);
+ *p = NULL;
+ }
+}
+
+
/*
* Used in a few places, so in one function for clarity.
*/