aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorteor <teor@torproject.org>2019-03-18 11:29:20 +1000
committerteor <teor@torproject.org>2019-03-18 11:29:20 +1000
commit55865a2c9c9929b690a4f5a969afd5d4415c40bd (patch)
tree73cc8806baa3eef720023a6b29030cfc5a51ad0d
parent5d41e2223f64517300aad168b2f2479ba00ac10b (diff)
parentaec6ee201bbf63f54bcf879de10addf00779504c (diff)
downloadtor-55865a2c9c9929b690a4f5a969afd5d4415c40bd.tar.gz
tor-55865a2c9c9929b690a4f5a969afd5d4415c40bd.zip
Merge branch 'bug29706_034_minimal_merge' into bug29706_035_minimal_merge
-rw-r--r--changes/bug29706_minimal4
-rw-r--r--src/feature/dirauth/shared_random_state.c4
-rw-r--r--src/feature/dirauth/shared_random_state.h2
-rw-r--r--src/test/test_shared_random.c17
4 files changed, 22 insertions, 5 deletions
diff --git a/changes/bug29706_minimal b/changes/bug29706_minimal
new file mode 100644
index 0000000000..9d4a43326c
--- /dev/null
+++ b/changes/bug29706_minimal
@@ -0,0 +1,4 @@
+ o Minor bugfixes (memory management, testing):
+ - Stop leaking parts of the shared random state in the shared-random unit
+ tests. The previous fix in 29599 was incomplete.
+ Fixes bug 29706; bugfix on 0.2.9.1-alpha.
diff --git a/src/feature/dirauth/shared_random_state.c b/src/feature/dirauth/shared_random_state.c
index 2bc030f4a7..b3e4a4ef92 100644
--- a/src/feature/dirauth/shared_random_state.c
+++ b/src/feature/dirauth/shared_random_state.c
@@ -985,7 +985,7 @@ state_query(sr_state_action_t action, sr_state_object_t obj_type,
/* Delete the current SRV value from the state freeing it and the value is set
* to NULL meaning empty. */
-static void
+STATIC void
state_del_current_srv(void)
{
state_query(SR_STATE_ACTION_DEL, SR_STATE_OBJ_CURSRV, NULL, NULL);
@@ -993,7 +993,7 @@ state_del_current_srv(void)
/* Delete the previous SRV value from the state freeing it and the value is
* set to NULL meaning empty. */
-static void
+STATIC void
state_del_previous_srv(void)
{
state_query(SR_STATE_ACTION_DEL, SR_STATE_OBJ_PREVSRV, NULL, NULL);
diff --git a/src/feature/dirauth/shared_random_state.h b/src/feature/dirauth/shared_random_state.h
index 35626be3f6..08f999f9d4 100644
--- a/src/feature/dirauth/shared_random_state.h
+++ b/src/feature/dirauth/shared_random_state.h
@@ -140,6 +140,8 @@ STATIC int is_phase_transition(sr_phase_t next_phase);
STATIC void set_sr_phase(sr_phase_t phase);
STATIC sr_state_t *get_sr_state(void);
+STATIC void state_del_previous_srv(void);
+STATIC void state_del_current_srv(void);
#endif /* defined(TOR_UNIT_TESTS) */
diff --git a/src/test/test_shared_random.c b/src/test/test_shared_random.c
index 1fb3179840..b4fe6eef64 100644
--- a/src/test/test_shared_random.c
+++ b/src/test/test_shared_random.c
@@ -74,6 +74,9 @@ init_authority_state(void)
* the phase we are currently in which uses "now" as the starting
* timestamp. Delete it before we do any testing below. */
sr_state_delete_commits();
+ /* It's also possible that a current SRV has been generated, if we are at
+ * state transition time. But let's just forget about that SRV. */
+ sr_state_clean_srvs();
done:
UNMOCK(get_my_v3_authority_cert);
@@ -588,12 +591,20 @@ test_encoding(void *arg)
;
}
-/** Setup some SRVs in our SR state. If <b>also_current</b> is set, then set
- * both current and previous SRVs.
- * Helper of test_vote() and test_sr_compute_srv(). */
+/** Setup some SRVs in our SR state.
+ * If <b>also_current</b> is set, then set both current and previous SRVs.
+ * Otherwise, just set the previous SRV. (And clear the current SRV.)
+ *
+ * You must call sr_state_free_all() to free the state at the end of each test
+ * function (on pass or fail). */
static void
test_sr_setup_srv(int also_current)
{
+ /* Clear both SRVs before starting.
+ * In 0.3.5 and earlier, sr_state_set_previous_srv() and
+ * sr_state_set_current_srv() do not free() the old srvs. */
+ sr_state_clean_srvs();
+
sr_srv_t *srv = tor_malloc_zero(sizeof(sr_srv_t));
srv->num_reveals = 42;
memcpy(srv->value,