From 47654d32497acae23aafbe3316ae73d3c00429c8 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 23 Jul 2019 12:04:59 -0400 Subject: Refactor config free logic to use a single path. The right way to free a config object is now to wrap config_free(), always. Instead of creating an alternative free function, objects should provide an alternative clear callback to free any fields that the configuration manager doesn't manage. This lets us simplify our code a little, and lets us extend the confparse.c code to manage additional fields in config_free. --- src/app/config/confparse.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/app/config/confparse.c') diff --git a/src/app/config/confparse.c b/src/app/config/confparse.c index 998c0e6ef2..8e3ad7fafd 100644 --- a/src/app/config/confparse.c +++ b/src/app/config/confparse.c @@ -789,6 +789,10 @@ config_free_(const config_mgr_t *mgr, void *options) tor_assert(fmt); + if (mgr->toplevel->clear_fn) { + mgr->toplevel->clear_fn(mgr, options); + } + SMARTLIST_FOREACH_BEGIN(mgr->all_vars, const managed_var_t *, mv) { config_clear(mgr, options, mv); } SMARTLIST_FOREACH_END(mv); @@ -977,9 +981,7 @@ config_dump(const config_mgr_t *mgr, const void *default_options, result = smartlist_join_strings(elements, "", 0, NULL); SMARTLIST_FOREACH(elements, char *, cp, tor_free(cp)); smartlist_free(elements); - if (defaults_tmp) { - fmt->free_fn(mgr, defaults_tmp); - } + config_free(mgr, defaults_tmp); return result; } -- cgit v1.2.3-54-g00ecf