Convert remaining function (mostly static) to new free style

This commit is contained in:
Nick Mathewson 2017-12-08 10:21:12 -05:00
parent 17dcce3fe1
commit fa0d24286b
34 changed files with 227 additions and 104 deletions

View File

@ -1905,9 +1905,12 @@ tor_passwd_dup(const struct passwd *pw)
return new_pw;
}
#define tor_passwd_free(pw) \
FREE_AND_NULL(struct passwd, tor_passwd_free_, (pw))
/** Helper: free one of our cached 'struct passwd' values. */
static void
tor_passwd_free(struct passwd *pw)
tor_passwd_free_(struct passwd *pw)
{
if (!pw)
return;

View File

@ -1163,19 +1163,26 @@ HT_GENERATE2(digest256map_impl, digest256map_entry_t, node,
digest256map_entry_hash,
digest256map_entries_eq, 0.6, tor_reallocarray_, tor_free_)
#define strmap_entry_free(ent) \
FREE_AND_NULL(strmap_entry_t, strmap_entry_free_, (ent))
#define digestmap_entry_free(ent) \
FREE_AND_NULL(digestmap_entry_t, digestmap_entry_free_, (ent))
#define digest256map_entry_free(ent) \
FREE_AND_NULL(digest256map_entry_t, digest256map_entry_free_, (ent))
static inline void
strmap_entry_free(strmap_entry_t *ent)
strmap_entry_free_(strmap_entry_t *ent)
{
tor_free(ent->key);
tor_free(ent);
}
static inline void
digestmap_entry_free(digestmap_entry_t *ent)
digestmap_entry_free_(digestmap_entry_t *ent)
{
tor_free(ent);
}
static inline void
digest256map_entry_free(digest256map_entry_t *ent)
digest256map_entry_free_(digest256map_entry_t *ent)
{
tor_free(ent);
}

View File

@ -387,9 +387,12 @@ pending_log_message_new(int severity, log_domain_mask_t domain,
return m;
}
#define pending_log_message_free(msg) \
FREE_AND_NULL(pending_log_message_t, pending_log_message_free_, (msg))
/** Release all storage held by <b>msg</b>. */
static void
pending_log_message_free(pending_log_message_t *msg)
pending_log_message_free_(pending_log_message_t *msg)
{
if (!msg)
return;

View File

@ -1446,8 +1446,12 @@ cached_getaddrinfo_items_eq(const cached_getaddrinfo_item_t *a,
return (a->family == b->family) && 0 == strcmp(a->name, b->name);
}
#define cached_getaddrinfo_item_free(item) \
FREE_AND_NULL(cached_getaddrinfo_item_t, \
cached_getaddrinfo_item_free_, (item))
static void
cached_getaddrinfo_item_free(cached_getaddrinfo_item_t *item)
cached_getaddrinfo_item_free_(cached_getaddrinfo_item_t *item)
{
if (item == NULL)
return;

View File

@ -148,12 +148,15 @@ workqueue_entry_new(workqueue_reply_t (*fn)(void*, void*),
return ent;
}
#define workqueue_entry_free(ent) \
FREE_AND_NULL(workqueue_entry_t, workqueue_entry_free_, (ent))
/**
* Release all storage held in <b>ent</b>. Call only when <b>ent</b> is not on
* any queue.
*/
static void
workqueue_entry_free(workqueue_entry_t *ent)
workqueue_entry_free_(workqueue_entry_t *ent)
{
if (!ent)
return;

View File

@ -90,34 +90,47 @@ addressmap_init(void)
virtaddress_reversemap = strmap_new();
}
#define addressmap_ent_free(ent) \
FREE_AND_NULL(addressmap_entry_t, addressmap_ent_free_, (ent))
/** Free the memory associated with the addressmap entry <b>_ent</b>. */
static void
addressmap_ent_free(void *_ent)
addressmap_ent_free_(addressmap_entry_t *ent)
{
addressmap_entry_t *ent;
if (!_ent)
if (!ent)
return;
ent = _ent;
tor_free(ent->new_address);
tor_free(ent);
}
static void
addressmap_ent_free_void(void *ent)
{
addressmap_ent_free_(ent);
}
#define addressmap_virtaddress_ent_free(ent) \
FREE_AND_NULL(virtaddress_entry_t, addressmap_virtaddress_ent_free_, (ent))
/** Free storage held by a virtaddress_entry_t* entry in <b>_ent</b>. */
static void
addressmap_virtaddress_ent_free(void *_ent)
addressmap_virtaddress_ent_free_(virtaddress_entry_t *ent)
{
virtaddress_entry_t *ent;
if (!_ent)
if (!ent)
return;
ent = _ent;
tor_free(ent->ipv4_address);
tor_free(ent->ipv6_address);
tor_free(ent->hostname_address);
tor_free(ent);
}
static void
addressmap_virtaddress_ent_free_void(void *ent)
{
addressmap_virtaddress_ent_free_(ent);
}
/** Remove <b>address</b> (which must map to <b>ent</b>) from the
* virtual address map. */
static void
@ -311,10 +324,10 @@ addressmap_clean(time_t now)
void
addressmap_free_all(void)
{
strmap_free(addressmap, addressmap_ent_free);
strmap_free(addressmap, addressmap_ent_free_void);
addressmap = NULL;
strmap_free(virtaddress_reversemap, addressmap_virtaddress_ent_free);
strmap_free(virtaddress_reversemap, addressmap_virtaddress_ent_free_void);
virtaddress_reversemap = NULL;
}

View File

@ -53,7 +53,10 @@ struct bridge_info_t {
smartlist_t *socks_args;
};
static void bridge_free(bridge_info_t *bridge);
#define bridge_free(bridge) \
FREE_AND_NULL(bridge_info_t, bridge_free_, (bridge))
static void bridge_free_(bridge_info_t *bridge);
static void rewrite_node_address_for_bridge(const bridge_info_t *bridge,
node_t *node);
@ -101,7 +104,7 @@ clear_bridge_list(void)
/** Free the bridge <b>bridge</b>. */
static void
bridge_free(bridge_info_t *bridge)
bridge_free_(bridge_info_t *bridge)
{
if (!bridge)
return;

View File

@ -226,12 +226,11 @@ static void channel_remove_from_digest_map(channel_t *chan);
static ssize_t
channel_flush_some_cells_from_outgoing_queue(channel_t *chan,
ssize_t num_cells);
static void channel_force_free(channel_t *chan);
static void
channel_free_list(smartlist_t *channels, int mark_for_close);
static void
channel_listener_free_list(smartlist_t *channels, int mark_for_close);
static void channel_listener_force_free(channel_listener_t *chan_l);
static void channel_force_xfree(channel_t *chan);
static void channel_free_list(smartlist_t *channels, int mark_for_close);
static void channel_listener_free_list(smartlist_t *channels,
int mark_for_close);
static void channel_listener_force_xfree(channel_listener_t *chan_l);
static size_t channel_get_cell_queue_entry_size(channel_t *chan,
cell_queue_entry_t *q);
static void
@ -1068,7 +1067,7 @@ channel_listener_free_(channel_listener_t *chan_l)
*/
static void
channel_force_free(channel_t *chan)
channel_force_xfree(channel_t *chan)
{
cell_queue_entry_t *cell, *cell_tmp;
tor_assert(chan);
@ -1106,13 +1105,13 @@ channel_force_free(channel_t *chan)
/* We might still have a cell queue; kill it */
TOR_SIMPLEQ_FOREACH_SAFE(cell, &chan->incoming_queue, next, cell_tmp) {
cell_queue_entry_free(cell, 0);
cell_queue_entry_xfree(cell, 0);
}
TOR_SIMPLEQ_INIT(&chan->incoming_queue);
/* Outgoing cell queue is similar, but we can have to free packed cells */
TOR_SIMPLEQ_FOREACH_SAFE(cell, &chan->outgoing_queue, next, cell_tmp) {
cell_queue_entry_free(cell, 0);
cell_queue_entry_xfree(cell, 0);
}
TOR_SIMPLEQ_INIT(&chan->outgoing_queue);
@ -1126,7 +1125,7 @@ channel_force_free(channel_t *chan)
*/
static void
channel_listener_force_free(channel_listener_t *chan_l)
channel_listener_force_xfree(channel_listener_t *chan_l)
{
tor_assert(chan_l);
@ -1755,7 +1754,7 @@ cell_queue_entry_dup(cell_queue_entry_t *q)
*/
STATIC void
cell_queue_entry_free(cell_queue_entry_t *q, int handed_off)
cell_queue_entry_xfree(cell_queue_entry_t *q, int handed_off)
{
if (!q) return;
@ -2563,7 +2562,7 @@ channel_flush_some_cells_from_outgoing_queue(channel_t *chan,
/* Update the channel's queue size too */
chan->bytes_in_queue -= cell_size;
/* Finally, free q */
cell_queue_entry_free(q, handed_off);
cell_queue_entry_xfree(q, handed_off);
q = NULL;
} else {
/* No cell removed from list, so we can't go on any further */
@ -3297,7 +3296,7 @@ channel_free_list(smartlist_t *channels, int mark_for_close)
if (!CHANNEL_CONDEMNED(curr)) {
channel_mark_for_close(curr);
}
channel_force_free(curr);
channel_force_xfree(curr);
} else channel_free(curr);
} SMARTLIST_FOREACH_END(curr);
}
@ -3326,7 +3325,7 @@ channel_listener_free_list(smartlist_t *listeners, int mark_for_close)
curr->state == CHANNEL_LISTENER_STATE_ERROR)) {
channel_listener_mark_for_close(curr);
}
channel_listener_force_free(curr);
channel_listener_force_xfree(curr);
} else channel_listener_free(curr);
} SMARTLIST_FOREACH_END(curr);
}

View File

@ -483,7 +483,7 @@ struct cell_queue_entry_s {
/* Cell queue functions for benefit of test suite */
STATIC int chan_cell_queue_len(const chan_cell_queue_t *queue);
STATIC void cell_queue_entry_free(cell_queue_entry_t *q, int handed_off);
STATIC void cell_queue_entry_xfree(cell_queue_entry_t *q, int handed_off);
void channel_write_cell_generic_(channel_t *chan, const char *cell_type,
void *cell, cell_queue_entry_t *q);

View File

@ -922,7 +922,7 @@ get_short_version(void)
/** Release additional memory allocated in options
*/
STATIC void
or_options_free(or_options_t *options)
or_options_free_(or_options_t *options)
{
if (!options)
return;
@ -6506,7 +6506,7 @@ port_cfg_new(size_t namelen)
/** Free all storage held in <b>port</b> */
STATIC void
port_cfg_free(port_cfg_t *port)
port_cfg_free_(port_cfg_t *port)
{
tor_free(port);
}

View File

@ -177,8 +177,12 @@ extern struct config_format_t options_format;
#endif
STATIC port_cfg_t *port_cfg_new(size_t namelen);
STATIC void port_cfg_free(port_cfg_t *port);
STATIC void or_options_free(or_options_t *options);
#define port_cfg_free(port) \
FREE_AND_NULL(port_cfg_t, port_cfg_free_, (port))
STATIC void port_cfg_free_(port_cfg_t *port);
#define or_options_free(opt) \
FREE_AND_NULL(or_options_t, or_options_free_, (opt))
STATIC void or_options_free_(or_options_t *options);
STATIC int options_validate_single_onion(or_options_t *options,
char **msg);
STATIC int options_validate(or_options_t *old_options,

View File

@ -207,9 +207,12 @@ HT_PROTOTYPE(cdm_diff_ht, cdm_diff_t, node, cdm_diff_hash, cdm_diff_eq)
HT_GENERATE2(cdm_diff_ht, cdm_diff_t, node, cdm_diff_hash, cdm_diff_eq,
0.6, tor_reallocarray, tor_free_)
#define cdm_diff_free(diff) \
FREE_AND_NULL(cdm_diff_t, cdm_diff_free_, (diff))
/** Release all storage held in <b>diff</b>. */
static void
cdm_diff_free(cdm_diff_t *diff)
cdm_diff_free_(cdm_diff_t *diff)
{
if (!diff)
return;
@ -1502,11 +1505,15 @@ consensus_diff_worker_threadfn(void *state_, void *work_)
return WQ_RPL_REPLY;
}
#define consensus_diff_worker_job_free(job) \
FREE_AND_NULL(consensus_diff_worker_job_t, \
consensus_diff_worker_job_free_, (job))
/**
* Helper: release all storage held in <b>job</b>.
*/
static void
consensus_diff_worker_job_free(consensus_diff_worker_job_t *job)
consensus_diff_worker_job_free_(consensus_diff_worker_job_t *job)
{
if (!job)
return;
@ -1649,11 +1656,15 @@ typedef struct consensus_compress_worker_job_t {
compressed_result_t out[ARRAY_LENGTH(compress_consensus_with)];
} consensus_compress_worker_job_t;
#define consensus_compress_worker_job_free(job) \
FREE_AND_NULL(consensus_compress_worker_job_t, \
consensus_compress_worker_job_free_, (job))
/**
* Free all resources held in <b>job</b>
*/
static void
consensus_compress_worker_job_free(consensus_compress_worker_job_t *job)
consensus_compress_worker_job_free_(consensus_compress_worker_job_t *job)
{
if (!job)
return;

View File

@ -783,9 +783,12 @@ queue_control_event_string,(uint16_t event, char *msg))
}
}
#define queued_event_free(ev) \
FREE_AND_NULL(queued_event_t, queued_event_free_, (ev))
/** Release all storage held by <b>ev</b>. */
static void
queued_event_free(queued_event_t *ev)
queued_event_free_(queued_event_t *ev)
{
if (ev == NULL)
return;

View File

@ -48,14 +48,25 @@ worker_state_new(void *arg)
ws->onion_keys = server_onion_keys_new();
return ws;
}
#define worker_state_free(ws) \
FREE_AND_NULL(worker_state_t, worker_state_free_, (ws))
static void
worker_state_free(void *arg)
worker_state_free_(worker_state_t *ws)
{
worker_state_t *ws = arg;
if (!ws)
return;
server_onion_keys_free(ws->onion_keys);
tor_free(ws);
}
static void
worker_state_free_void(void *arg)
{
worker_state_free_(arg);
}
static replyqueue_t *replyqueue = NULL;
static threadpool_t *threadpool = NULL;
static struct event *reply_event = NULL;
@ -102,7 +113,7 @@ cpu_init(void)
threadpool = threadpool_new(n_threads,
replyqueue,
worker_state_new,
worker_state_free,
worker_state_free_void,
NULL);
}
/* Total voodoo. Can we make this more sensible? */
@ -198,7 +209,7 @@ cpuworkers_rotate_keyinfo(void)
if (threadpool_queue_update(threadpool,
worker_state_new,
update_state_threadfn,
worker_state_free,
worker_state_free_void,
NULL)) {
log_warn(LD_OR, "Failed to queue key update for worker threads.");
}

View File

@ -41,9 +41,12 @@ typedef struct ddmap_entry_s {
vote_routerstatus_t *vrs_lst[FLEXIBLE_ARRAY_MEMBER];
} ddmap_entry_t;
#define ddmap_entry_free(e) \
FREE_AND_NULL(ddmap_entry_t, ddmap_entry_free_, (e))
/** Release all storage held by e. */
static void
ddmap_entry_free(ddmap_entry_t *e)
ddmap_entry_free_(ddmap_entry_t *e)
{
tor_free(e);
}

View File

@ -2843,10 +2843,13 @@ get_voting_schedule(const or_options_t *options, time_t now, int severity)
return new_voting_schedule;
}
#define voting_schedule_free(s) \
FREE_AND_NULL(voting_schedule_t, voting_schedule_free_, (s))
/** Frees a voting_schedule_t. This should be used instead of the generic
* tor_free. */
static void
voting_schedule_free(voting_schedule_t *voting_schedule_to_free)
voting_schedule_free_(voting_schedule_t *voting_schedule_to_free)
{
if (!voting_schedule_to_free)
return;

View File

@ -2206,7 +2206,7 @@ entry_guard_restriction_free_(entry_guard_restriction_t *rst)
* Release all storage held in <b>state</b>.
*/
void
circuit_guard_state_free(circuit_guard_state_t *state)
circuit_guard_state_free_(circuit_guard_state_t *state)
{
if (!state)
return;
@ -3109,7 +3109,7 @@ get_guard_state_for_bridge_desc_fetch(const char *digest)
/** Release all storage held by <b>e</b>. */
STATIC void
entry_guard_free(entry_guard_t *e)
entry_guard_free_(entry_guard_t *e)
{
if (!e)
return;

View File

@ -356,7 +356,10 @@ typedef enum {
GUARD_USAGE_DIRGUARD = 1
} guard_usage_t;
void circuit_guard_state_free(circuit_guard_state_t *state);
#define circuit_guard_state_free(val) \
FREE_AND_NULL(circuit_guard_state_t, circuit_guard_state_free_, (val))
void circuit_guard_state_free_(circuit_guard_state_t *state);
int entry_guard_pick_for_circuit(guard_selection_t *gs,
guard_usage_t usage,
entry_guard_restriction_t *rst,
@ -509,7 +512,9 @@ STATIC entry_guard_t *entry_guard_add_to_sample(guard_selection_t *gs,
STATIC entry_guard_t *entry_guards_expand_sample(guard_selection_t *gs);
STATIC char *entry_guard_encode_for_state(entry_guard_t *guard);
STATIC entry_guard_t *entry_guard_parse_from_state(const char *s);
STATIC void entry_guard_free(entry_guard_t *e);
#define entry_guard_free(e) \
FREE_AND_NULL(entry_guard_t, entry_guard_free_, (e))
STATIC void entry_guard_free_(entry_guard_t *e);
STATIC void entry_guards_update_filtered_sets(guard_selection_t *gs);
STATIC int entry_guards_all_primary_guards_are_down(guard_selection_t *gs);
/**

View File

@ -40,7 +40,7 @@ ext_or_cmd_new(uint16_t len)
/** Deallocate the Extended ORPort message in <b>cmd</b>. */
void
ext_or_cmd_free(ext_or_cmd_t *cmd)
ext_or_cmd_free_(ext_or_cmd_t *cmd)
{
tor_free(cmd);
}

View File

@ -10,7 +10,11 @@
int connection_ext_or_start_auth(or_connection_t *or_conn);
ext_or_cmd_t *ext_or_cmd_new(uint16_t len);
void ext_or_cmd_free(ext_or_cmd_t *cmd);
#define ext_or_cmd_free(cmd) \
FREE_AND_NULL(ext_or_cmd_t, ext_or_cmd_free_, (cmd))
void ext_or_cmd_free_(ext_or_cmd_t *cmd);
void connection_or_set_ext_or_identifier(or_connection_t *conn);
void connection_or_remove_from_ext_or_id_map(or_connection_t *conn);
void connection_or_clear_ext_or_id_map(void);

View File

@ -527,9 +527,12 @@ HT_PROTOTYPE(clientmap, clientmap_entry_t, node, clientmap_entry_hash,
HT_GENERATE2(clientmap, clientmap_entry_t, node, clientmap_entry_hash,
clientmap_entries_eq, 0.6, tor_reallocarray_, tor_free_)
#define clientmap_entry_free(ent) \
FREE_AND_NULL(clientmap_entry_t, clientmap_entry_free_, ent)
/** Free all storage held by <b>ent</b>. */
static void
clientmap_entry_free(clientmap_entry_t *ent)
clientmap_entry_free_(clientmap_entry_t *ent)
{
if (!ent)
return;

View File

@ -52,9 +52,12 @@ lookup_v3_desc_as_dir(const uint8_t *key)
return digest256map_get(hs_cache_v3_dir, key);
}
#define cache_dir_desc_free(val) \
FREE_AND_NULL(hs_cache_dir_descriptor_t, cache_dir_desc_free_, (val))
/* Free a directory descriptor object. */
static void
cache_dir_desc_free(hs_cache_dir_descriptor_t *desc)
cache_dir_desc_free_(hs_cache_dir_descriptor_t *desc)
{
if (desc == NULL) {
return;
@ -67,10 +70,9 @@ cache_dir_desc_free(hs_cache_dir_descriptor_t *desc)
/* Helper function: Use by the free all function using the digest256map
* interface to cache entries. */
static void
cache_dir_desc_free_(void *ptr)
cache_dir_desc_free_void(void *ptr)
{
hs_cache_dir_descriptor_t *desc = ptr;
cache_dir_desc_free(desc);
cache_dir_desc_free_(ptr);
}
/* Create a new directory cache descriptor object from a encoded descriptor.
@ -417,9 +419,12 @@ cache_client_desc_new(const char *desc_str,
return client_desc;
}
#define cache_client_desc_free(val) \
FREE_AND_NULL(hs_cache_client_descriptor_t, cache_client_desc_free_, (val))
/** Free memory allocated by <b>desc</b>. */
static void
cache_client_desc_free(hs_cache_client_descriptor_t *desc)
cache_client_desc_free_(hs_cache_client_descriptor_t *desc)
{
if (desc == NULL) {
return;
@ -433,7 +438,7 @@ cache_client_desc_free(hs_cache_client_descriptor_t *desc)
/** Helper function: Use by the free all function to clear the client cache */
static void
cache_client_desc_free_(void *ptr)
cache_client_desc_free_void(void *ptr)
{
hs_cache_client_descriptor_t *desc = ptr;
cache_client_desc_free(desc);
@ -448,18 +453,21 @@ cache_intro_state_new(void)
return state;
}
#define cache_intro_state_free(val) \
FREE_AND_NULL(hs_cache_intro_state_t, cache_intro_state_free_, (val))
/* Free an hs_cache_intro_state_t object. */
static void
cache_intro_state_free(hs_cache_intro_state_t *state)
cache_intro_state_free_(hs_cache_intro_state_t *state)
{
tor_free(state);
}
/* Helper function: use by the free all function. */
static void
cache_intro_state_free_(void *state)
cache_intro_state_free_void(void *state)
{
cache_intro_state_free(state);
cache_intro_state_free_(state);
}
/* Return a newly allocated and initialized hs_cache_client_intro_state_t
@ -472,22 +480,26 @@ cache_client_intro_state_new(void)
return cache;
}
#define cache_client_intro_state_free(val) \
FREE_AND_NULL(hs_cache_client_intro_state_t, \
cache_client_intro_state_free_, (val))
/* Free a cache client intro state object. */
static void
cache_client_intro_state_free(hs_cache_client_intro_state_t *cache)
cache_client_intro_state_free_(hs_cache_client_intro_state_t *cache)
{
if (cache == NULL) {
return;
}
digest256map_free(cache->intro_points, cache_intro_state_free_);
digest256map_free(cache->intro_points, cache_intro_state_free_void);
tor_free(cache);
}
/* Helper function: use by the free all function. */
static void
cache_client_intro_state_free_(void *entry)
cache_client_intro_state_free_void(void *entry)
{
cache_client_intro_state_free(entry);
cache_client_intro_state_free_(entry);
}
/* For the given service identity key service_pk and an introduction
@ -933,14 +945,14 @@ hs_cache_init(void)
void
hs_cache_free_all(void)
{
digest256map_free(hs_cache_v3_dir, cache_dir_desc_free_);
digest256map_free(hs_cache_v3_dir, cache_dir_desc_free_void);
hs_cache_v3_dir = NULL;
digest256map_free(hs_cache_v3_client, cache_client_desc_free_);
digest256map_free(hs_cache_v3_client, cache_client_desc_free_void);
hs_cache_v3_client = NULL;
digest256map_free(hs_cache_client_intro_state,
cache_client_intro_state_free_);
cache_client_intro_state_free_void);
hs_cache_client_intro_state = NULL;
}

View File

@ -106,9 +106,12 @@ hs_token_new(hs_token_type_t type, size_t token_len,
return hs_token;
}
#define hs_token_free(val) \
FREE_AND_NULL(hs_token_t, hs_token_free_, (val))
/** Free memory allocated by this <b>hs_token</b>. */
static void
hs_token_free(hs_token_t *hs_token)
hs_token_free_(hs_token_t *hs_token)
{
if (!hs_token) {
return;

View File

@ -65,7 +65,9 @@
#include <string.h>
static void nodelist_drop_node(node_t *node, int remove_from_ht);
static void node_free(node_t *node);
#define node_free(val) \
FREE_AND_NULL(node_t, node_free_, (val))
static void node_free_(node_t *node);
/** count_usable_descriptors counts descriptors with these flag(s)
*/
@ -656,7 +658,7 @@ nodelist_find_nodes_with_microdesc(const microdesc_t *md)
/** Release storage held by <b>node</b> */
static void
node_free(node_t *node)
node_free_(node_t *node)
{
if (!node)
return;

View File

@ -1102,18 +1102,22 @@ rend_client_lookup_service_authorization(const char *onion_address)
return strmap_get(auth_hid_servs, onion_address);
}
#define rend_service_authorization_free(val) \
FREE_AND_NULL(rend_service_authorization_t, \
rend_service_authorization_free_, (val))
/** Helper: Free storage held by rend_service_authorization_t. */
static void
rend_service_authorization_free(rend_service_authorization_t *auth)
rend_service_authorization_free_(rend_service_authorization_t *auth)
{
tor_free(auth);
}
/** Helper for strmap_free. */
static void
rend_service_authorization_strmap_item_free(void *service_auth)
rend_service_authorization_free_void(void *service_auth)
{
rend_service_authorization_free(service_auth);
rend_service_authorization_free_(service_auth);
}
/** Release all the storage held in auth_hid_servs.
@ -1124,7 +1128,7 @@ rend_service_authorization_free_all(void)
if (!auth_hid_servs) {
return;
}
strmap_free(auth_hid_servs, rend_service_authorization_strmap_item_free);
strmap_free(auth_hid_servs, rend_service_authorization_free_void);
auth_hid_servs = NULL;
}
@ -1199,7 +1203,7 @@ rend_parse_service_authorization(const or_options_t *options,
rend_service_authorization_free_all();
auth_hid_servs = parsed;
} else {
strmap_free(parsed, rend_service_authorization_strmap_item_free);
strmap_free(parsed, rend_service_authorization_free_void);
}
return res;
}

View File

@ -172,7 +172,7 @@ rend_authorized_client_free_(rend_authorized_client_t *client)
/** Helper for strmap_free. */
static void
rend_authorized_client_strmap_item_free(void *authorized_client)
rend_authorized_client_free_void(void *authorized_client)
{
rend_authorized_client_free_(authorized_client);
}
@ -1675,7 +1675,7 @@ rend_service_load_auth_keys(rend_service_t *s, const char *hfname)
memwipe(client_keys_str, 0, strlen(client_keys_str));
tor_free(client_keys_str);
}
strmap_free(parsed_clients, rend_authorized_client_strmap_item_free);
strmap_free(parsed_clients, rend_authorized_client_free_void);
if (cfname) {
memwipe(cfname, 0, strlen(cfname));

View File

@ -1358,9 +1358,12 @@ bw_array_new(void)
return b;
}
#define bw_array_free(val) \
FREE_AND_NULL(bw_array_t, bw_array_free_, (val))
/** Free storage held by bandwidth array <b>b</b>. */
static void
bw_array_free(bw_array_t *b)
bw_array_free_(bw_array_t *b)
{
if (!b) {
return;
@ -1883,7 +1886,7 @@ predicted_ports_init(void)
* be used.
*/
static void
predicted_ports_free(void)
predicted_ports_free_all(void)
{
rephist_total_alloc -=
smartlist_len(predicted_ports_list)*sizeof(predicted_port_t);
@ -2828,7 +2831,7 @@ HT_GENERATE2(bidimap, bidi_map_entry_t, node, bidi_map_ent_hash,
/* DOCDOC bidi_map_free */
static void
bidi_map_free(void)
bidi_map_free_all(void)
{
bidi_map_entry_t **ptr, **next, *ent;
for (ptr = HT_START(bidimap, &bidi_map); ptr; ptr = next) {
@ -2848,7 +2851,7 @@ rep_hist_reset_conn_stats(time_t now)
mostly_read = 0;
mostly_written = 0;
both_read_and_written = 0;
bidi_map_free();
bidi_map_free_all();
}
/** Stop collecting connection stats in a way that we can re-start doing
@ -3037,9 +3040,12 @@ hs_stats_new(void)
return new_hs_stats;
}
#define hs_stats_free(val) \
FREE_AND_NULL(hs_stats_t, hs_stats_free_, (val))
/** Free an hs_stats_t structure. */
static void
hs_stats_free(hs_stats_t *victim_hs_stats)
hs_stats_free_(hs_stats_t *victim_hs_stats)
{
if (!victim_hs_stats) {
return;
@ -3451,8 +3457,8 @@ rep_hist_free_all(void)
tor_free(exit_bytes_read);
tor_free(exit_bytes_written);
tor_free(exit_streams);
predicted_ports_free();
bidi_map_free();
predicted_ports_free_all();
bidi_map_free_all();
if (circuits_for_buffer_stats) {
SMARTLIST_FOREACH(circuits_for_buffer_stats, circ_buffer_stats_t *, s,

View File

@ -163,7 +163,6 @@ static const routerstatus_t *router_pick_dirserver_generic(
smartlist_t *sourcelist,
dirinfo_type_t type, int flags);
static void mark_all_dirservers_up(smartlist_t *server_list);
static void dir_server_free(dir_server_t *ds);
static int signed_desc_digest_is_recognized(signed_descriptor_t *desc);
static const char *signed_descriptor_get_body_impl(
const signed_descriptor_t *desc,
@ -447,9 +446,12 @@ download_status_for_authority_id_and_sk,(const char *id_digest,
return dl;
}
#define cert_list_free(val) \
FREE_AND_NULL(cert_list_t, cert_list_free_, (val))
/** Release all space held by a cert_list_t */
static void
cert_list_free(cert_list_t *cl)
cert_list_free_(cert_list_t *cl)
{
if (!cl)
return;
@ -465,7 +467,7 @@ cert_list_free(cert_list_t *cl)
static void
cert_list_free_void(void *cl)
{
cert_list_free(cl);
cert_list_free_(cl);
}
/** Reload the cached v3 key certificates from the cached-certs file in
@ -3210,9 +3212,12 @@ extrainfo_free_(extrainfo_t *extrainfo)
tor_free(extrainfo);
}
#define signed_descriptor_free(val) \
FREE_AND_NULL(signed_descriptor_t, signed_descriptor_free_, (val))
/** Release storage held by <b>sd</b>. */
static void
signed_descriptor_free(signed_descriptor_t *sd)
signed_descriptor_free_(signed_descriptor_t *sd)
{
if (!sd)
return;
@ -4752,9 +4757,12 @@ authority_cert_free_(authority_cert_t *cert)
tor_free(cert);
}
#define dir_server_free(val) \
FREE_AND_NULL(dir_server_t, dir_server_free_, (val))
/** Free storage held in <b>ds</b>. */
static void
dir_server_free(dir_server_t *ds)
dir_server_free_(dir_server_t *ds)
{
if (!ds)
return;

View File

@ -461,7 +461,7 @@ kist_free_all(void)
/* Function of the scheduler interface: on_channel_free() */
static void
kist_on_channel_free(const channel_t *chan)
kist_on_channel_free_fn(const channel_t *chan)
{
free_socket_info_by_chan(&socket_table, chan);
}
@ -724,7 +724,7 @@ kist_scheduler_run(void)
static scheduler_t kist_scheduler = {
.type = SCHEDULER_KIST,
.free_all = kist_free_all,
.on_channel_free = kist_on_channel_free,
.on_channel_free = kist_on_channel_free_fn,
.init = kist_scheduler_init,
.on_new_consensus = kist_scheduler_on_new_consensus,
.schedule = kist_scheduler_schedule,

View File

@ -384,7 +384,7 @@ commit_encode(const sr_commit_t *commit, char *dst, size_t len)
static void
sr_cleanup(void)
{
sr_state_free();
sr_state_free_all();
}
/* Using <b>commit</b>, return a newly allocated string containing the commit

View File

@ -274,9 +274,12 @@ commit_free_(void *p)
sr_commit_free_(p);
}
#define state_free(val) \
FREE_AND_NULL(sr_state_t, state_free_, (val))
/* Free a state that was allocated with state_new(). */
static void
state_free(sr_state_t *state)
state_free_(sr_state_t *state)
{
if (state == NULL) {
return;
@ -318,9 +321,12 @@ state_set(sr_state_t *state)
sr_state = state;
}
#define disk_state_free(val) \
FREE_AND_NULL(sr_disk_state_t, disk_state_free_, (val))
/* Free an allocated disk state. */
static void
disk_state_free(sr_disk_state_t *state)
disk_state_free_(sr_disk_state_t *state)
{
if (state == NULL) {
return;
@ -1286,7 +1292,7 @@ sr_state_srv_is_fresh(void)
/* Cleanup and free our disk and memory state. */
void
sr_state_free(void)
sr_state_free_all(void)
{
state_free(sr_state);
disk_state_free(sr_disk_state);

View File

@ -119,7 +119,7 @@ void sr_state_unset_fresh_srv(void);
int sr_state_init(int save_to_disk, int read_from_disk);
int sr_state_is_initialized(void);
void sr_state_save(void);
void sr_state_free(void);
void sr_state_free_all(void);
time_t sr_state_get_start_time_of_current_protocol_run(time_t now);
unsigned int sr_state_get_phase_duration(void);

View File

@ -443,10 +443,10 @@ free_fake_channel(channel_t *chan)
circuitmux_free(chan->cmux);
TOR_SIMPLEQ_FOREACH_SAFE(cell, &chan->incoming_queue, next, cell_tmp) {
cell_queue_entry_free(cell, 0);
cell_queue_entry_xfree(cell, 0);
}
TOR_SIMPLEQ_FOREACH_SAFE(cell, &chan->outgoing_queue, next, cell_tmp) {
cell_queue_entry_free(cell, 0);
cell_queue_entry_xfree(cell, 0);
}
tor_free(chan);

View File

@ -1351,7 +1351,7 @@ test_state_update(void *arg)
tt_assert(state->current_srv);
done:
sr_state_free();
sr_state_free_all();
UNMOCK(get_my_v3_authority_cert);
}