diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-07-23 12:04:59 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-08-28 09:40:53 -0400 |
commit | 47654d32497acae23aafbe3316ae73d3c00429c8 (patch) | |
tree | 9d9bb68efe2587b033eef4de945c4d887b2cfd76 /src/app/config/config.c | |
parent | 3d1f9f583a45143c1259b8926f8c57fa57fc1efb (diff) | |
download | tor-47654d32497acae23aafbe3316ae73d3c00429c8.tar.gz tor-47654d32497acae23aafbe3316ae73d3c00429c8.zip |
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.
Diffstat (limited to 'src/app/config/config.c')
-rw-r--r-- | src/app/config/config.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/app/config/config.c b/src/app/config/config.c index 7aa253a6bf..cdf5fa266c 100644 --- a/src/app/config/config.c +++ b/src/app/config/config.c @@ -843,9 +843,9 @@ static void config_maybe_load_geoip_files_(const or_options_t *options, static int options_validate_cb(void *old_options, void *options, void *default_options, int from_setconf, char **msg); -static void options_free_cb(const config_mgr_t *, void *options); static void cleanup_protocol_warning_severity_level(void); static void set_protocol_warning_severity_level(int warning_severity); +static void options_clear_cb(const config_mgr_t *mgr, void *opts); /** Magic value for or_options_t. */ #define OR_OPTIONS_MAGIC 9090909 @@ -862,8 +862,8 @@ static const config_format_t options_format = { option_deprecation_notes_, option_vars_, options_validate_cb, - options_free_cb, - NULL + options_clear_cb, + NULL, }; /* @@ -1011,11 +1011,11 @@ set_options(or_options_t *new_val, char **msg) /** Release additional memory allocated in options */ -STATIC void -or_options_free_(or_options_t *options) +static void +options_clear_cb(const config_mgr_t *mgr, void *opts) { - if (!options) - return; + (void)mgr; + or_options_t *options = opts; routerset_free(options->ExcludeExitNodesUnion_); if (options->NodeFamilySets) { @@ -1038,6 +1038,13 @@ or_options_free_(or_options_t *options) tor_free(options->command_arg); tor_free(options->master_key_fname); config_free_lines(options->MyFamily); +} + +/** Release all memory allocated in options + */ +STATIC void +or_options_free_(or_options_t *options) +{ config_free(get_options_mgr(), options); } @@ -3164,14 +3171,6 @@ options_validate_cb(void *old_options, void *options, void *default_options, return rv; } -/** Callback to free an or_options_t */ -static void -options_free_cb(const config_mgr_t *mgr, void *options) -{ - (void)mgr; - or_options_free_(options); -} - #define REJECT(arg) \ STMT_BEGIN *msg = tor_strdup(arg); return -1; STMT_END #if defined(__GNUC__) && __GNUC__ <= 3 |