dirvote: Free vote commits in the dirauth module

In order to make sr_commit_free() only used by the dirauth module, this
commits moves the commits free from a vote object into the dirvote.c file
which is now only for the module.

The function does nothing if the module is disabled.

Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
David Goulet 2018-04-25 10:49:32 -04:00
parent 2963e65c30
commit 6ee6533fd8
3 changed files with 21 additions and 3 deletions

View File

@ -3899,3 +3899,16 @@ dirvote_parse_sr_commits(networkstatus_t *ns, smartlist_t *tokens)
} }
} }
/* For the given vote, free the shared random commits if any. */
void
dirvote_clear_commits(networkstatus_t *ns)
{
tor_assert(ns->type == NS_TYPE_VOTE);
if (ns->sr_info.commits) {
SMARTLIST_FOREACH(ns->sr_info.commits, sr_commit_t *, c,
sr_commit_free(c));
smartlist_free(ns->sr_info.commits);
}
}

View File

@ -100,6 +100,7 @@ void dirvote_act(const or_options_t *options, time_t now);
void dirvote_free_all(void); void dirvote_free_all(void);
void dirvote_parse_sr_commits(networkstatus_t *ns, smartlist_t *tokens); void dirvote_parse_sr_commits(networkstatus_t *ns, smartlist_t *tokens);
void dirvote_clear_commits(networkstatus_t *ns);
#else /* HAVE_MODULE_DIRAUTH */ #else /* HAVE_MODULE_DIRAUTH */
@ -122,6 +123,12 @@ dirvote_parse_sr_commits(networkstatus_t *ns, smartlist_t *tokens)
(void) tokens; (void) tokens;
} }
static inline void
dirvote_clear_commits(networkstatus_t *ns)
{
(void) ns;
}
#endif /* HAVE_MODULE_DIRAUTH */ #endif /* HAVE_MODULE_DIRAUTH */
void dirvote_recalculate_timing(const or_options_t *options, time_t now); void dirvote_recalculate_timing(const or_options_t *options, time_t now);

View File

@ -366,9 +366,7 @@ networkstatus_vote_free_(networkstatus_t *ns)
digestmap_free(ns->desc_digest_map, NULL); digestmap_free(ns->desc_digest_map, NULL);
if (ns->sr_info.commits) { if (ns->sr_info.commits) {
SMARTLIST_FOREACH(ns->sr_info.commits, sr_commit_t *, c, dirvote_clear_commits(ns);
sr_commit_free(c));
smartlist_free(ns->sr_info.commits);
} }
tor_free(ns->sr_info.previous_srv); tor_free(ns->sr_info.previous_srv);
tor_free(ns->sr_info.current_srv); tor_free(ns->sr_info.current_srv);