chiark / gitweb /
Some configuration-related memory hygeine.
[disorder] / lib / vector.c
index 6803a14483428728b7e26645a9528e3987ac9c33..65a84e024490b7c4ad3a613f072264eff95a1978 100644 (file)
@@ -15,7 +15,9 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-
+/** @file lib/vector.c
+ * @brief Dynamic array utilities
+ */
 #include "common.h"
 
 #include <stddef.h>
@@ -36,6 +38,19 @@ void dynstr_append_bytes(struct dynstr *v, const char *ptr, size_t n) {
   }
 }
 
+/** @brief Free a string list */
+void free_strings(int nvec, char **vec) {
+  for(int n = 0; n < nvec; ++n)
+    xfree(vec[n]);
+  xfree(vec);
+}
+
+/** @brief Free and re-initialize a vector */
+void vector_clear(struct vector *v) {
+  free_strings(v->nvec, v->vec);
+  vector_init(v);
+}
+
 /*
 Local Variables:
 c-basic-offset:2