Browse Source

opt: Add a function to free the internal memory.

Andreas Schlick 15 years ago
parent
commit
6a6f64f541
2 changed files with 14 additions and 0 deletions
  1. 6 0
      ccan/opt/opt.c
  2. 8 0
      ccan/opt/opt.h

+ 6 - 0
ccan/opt/opt.c

@@ -201,6 +201,12 @@ bool opt_parse(int *argc, char *argv[], void (*errlog)(const char *fmt, ...))
 	return (ret == 0);
 	return (ret == 0);
 }
 }
 
 
+void opt_free_table(void)
+{
+	free(opt_table);
+	opt_table=0;
+}
+
 void opt_log_stderr(const char *fmt, ...)
 void opt_log_stderr(const char *fmt, ...)
 {
 {
 	va_list ap;
 	va_list ap;

+ 8 - 0
ccan/opt/opt.h

@@ -183,6 +183,14 @@ void opt_register_table(const struct opt_table *table, const char *desc);
  */
  */
 bool opt_parse(int *argc, char *argv[], void (*errlog)(const char *fmt, ...));
 bool opt_parse(int *argc, char *argv[], void (*errlog)(const char *fmt, ...));
 
 
+/**
+ * opt_free_table - free the table.
+ *
+ * This frees the internal memory. Call this as the last
+ * opt function.
+ */
+void opt_free_table(void);
+
 /**
 /**
  * opt_log_stderr - print message to stderr.
  * opt_log_stderr - print message to stderr.
  * @fmt: printf-style format.
  * @fmt: printf-style format.