summaryrefslogtreecommitdiff
path: root/src/app/config/confparse.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-07-23 11:32:52 -0400
committerNick Mathewson <nickm@torproject.org>2019-08-28 09:40:53 -0400
commit38b770bbbb37aef6cd3cef5fd6f425cd951affe2 (patch)
tree65a613a67a7f9baf09c4f8cdcbe1e7efb8b613bb /src/app/config/confparse.c
parent47654d32497acae23aafbe3316ae73d3c00429c8 (diff)
downloadtor-38b770bbbb37aef6cd3cef5fd6f425cd951affe2.tar.gz
tor-38b770bbbb37aef6cd3cef5fd6f425cd951affe2.zip
Make a config_suite_t type to hold multiple config sub-objects
Right now, it doesn't do anything; this patch is meant to make sure that we're doing memory management correctly.
Diffstat (limited to 'src/app/config/confparse.c')
-rw-r--r--src/app/config/confparse.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/app/config/confparse.c b/src/app/config/confparse.c
index 8e3ad7fafd..d94a1d9ec9 100644
--- a/src/app/config/confparse.c
+++ b/src/app/config/confparse.c
@@ -72,6 +72,36 @@ managed_var_free_(managed_var_t *mv)
#define managed_var_free(mv) \
FREE_AND_NULL(managed_var_t, managed_var_free_, (mv))
+struct config_suite_t {
+ /* NOTE: This object isn't implemented yet; it's just a placeholder
+ * to make sure we have our memory menagement right.
+ */
+ int foo;
+};
+
+/**
+ * Allocate a new empty config_suite_t.
+ **/
+static config_suite_t *
+config_suite_new(void)
+{
+ config_suite_t *suite = tor_malloc_zero(sizeof(config_suite_t));
+ return suite;
+}
+
+/** Release all storage held by a config_suite_t. (Does not free
+ * any configuration objects it holds; the caller must do that first.) */
+static void
+config_suite_free_(config_suite_t *suite)
+{
+ if (!suite)
+ return;
+ tor_free(suite);
+}
+
+#define config_suite_free(suite) \
+ FREE_AND_NULL(config_suite_t, config_suite_free_, (suite))
+
struct config_mgr_t {
/** The 'top-level' configuration format. This one is used for legacy
* options that have not yet been assigned to different sub-modules.
@@ -152,6 +182,16 @@ config_mgr_register_fmt(config_mgr_t *mgr,
}
}
+/** Return a pointer to the config_suite_t * pointer inside a
+ * configuration object; returns NULL if there is no such member. */
+static inline config_suite_t **
+config_mgr_get_suite_ptr(const config_mgr_t *mgr, void *toplevel)
+{
+ if (mgr->toplevel->config_suite_offset < 0)
+ return NULL;
+ return STRUCT_VAR_P(toplevel, mgr->toplevel->config_suite_offset);
+}
+
/**
* Return a pointer to the configuration object within <b>toplevel</b> whose
* index is <b>idx</b>.
@@ -272,6 +312,10 @@ config_new(const config_mgr_t *mgr)
const config_format_t *fmt = mgr->toplevel;
void *opts = tor_malloc_zero(fmt->size);
struct_set_magic(opts, &mgr->toplevel_magic);
+ config_suite_t **suitep = config_mgr_get_suite_ptr(mgr, opts);
+ if (suitep) {
+ *suitep = config_suite_new();
+ }
CONFIG_CHECK(mgr, opts);
return opts;
}
@@ -802,6 +846,11 @@ config_free_(const config_mgr_t *mgr, void *options)
config_free_lines(*linep);
*linep = NULL;
}
+
+ config_suite_t **suitep = config_mgr_get_suite_ptr(mgr, options);
+ if (suitep)
+ config_suite_free(*suitep);
+
tor_free(options);
}