Added function cf_section_parse_free_strings, which should
authoraland <aland>
Wed, 17 Aug 2005 18:04:08 +0000 (18:04 +0000)
committeraland <aland>
Wed, 17 Aug 2005 18:04:08 +0000 (18:04 +0000)
help simplify each module's detach routines

src/include/conffile.h
src/main/conffile.c

index 0dc2e10..478761a 100644 (file)
@@ -48,7 +48,13 @@ void         cf_pair_free(CONF_PAIR **cp);
 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);
index 55aef77..a62880f 100644 (file)
@@ -836,6 +836,41 @@ int cf_section_parse(const CONF_SECTION *cs, void *base,
        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.
  */