diff options
author | David Goulet <dgoulet@torproject.org> | 2017-07-12 11:53:26 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2017-07-13 16:50:09 -0400 |
commit | 1b048fbfaadec04f409ab8d120106025b009fec8 (patch) | |
tree | 4d79fcd21a46b31c654614ccd8c0d1dab9b013e7 /src/or/hs_service.c | |
parent | 750c684fff02fde3054261abbbdcc6a458bea8e0 (diff) | |
download | tor-1b048fbfaadec04f409ab8d120106025b009fec8.tar.gz tor-1b048fbfaadec04f409ab8d120106025b009fec8.zip |
prop224: Add a clear configuration function
The added function frees any allocated pointers in a service configuration
object and reset all values to 0.
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/or/hs_service.c')
-rw-r--r-- | src/or/hs_service.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/or/hs_service.c b/src/or/hs_service.c index bfce7804ab..97d3288d17 100644 --- a/src/or/hs_service.c +++ b/src/or/hs_service.c @@ -149,6 +149,23 @@ set_service_default_config(hs_service_config_t *c, c->is_ephemeral = 0; } +/* From a service configuration object config, clear everything from it + * meaning free allocated pointers and reset the values. */ +static void +service_clear_config(hs_service_config_t *config) +{ + if (config == NULL) { + return; + } + tor_free(config->directory_path); + if (config->ports) { + SMARTLIST_FOREACH(config->ports, rend_service_port_config_t *, p, + rend_service_port_config_free(p);); + smartlist_free(config->ports); + } + memset(config, 0, sizeof(*config)); +} + /* Helper: Function that needs to return 1 for the HT for each loop which * frees every service in an hash map. */ static int @@ -592,12 +609,7 @@ hs_service_free(hs_service_t *service) } /* Free service configuration. */ - tor_free(service->config.directory_path); - if (service->config.ports) { - SMARTLIST_FOREACH(service->config.ports, rend_service_port_config_t *, p, - rend_service_port_config_free(p);); - smartlist_free(service->config.ports); - } + service_clear_config(&service->config); /* Wipe service keys. */ memwipe(&service->keys.identity_sk, 0, sizeof(service->keys.identity_sk)); |