]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
test/sr: Free SRVs before replacing them in test_sr_setup_srv()
authorteor <teor@torproject.org>
Sat, 9 Mar 2019 00:50:07 +0000 (10:50 +1000)
committerteor <teor@torproject.org>
Sat, 9 Mar 2019 01:59:52 +0000 (11:59 +1000)
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.

changes/bug29706_minimal [new file with mode: 0644]
src/or/shared_random_state.c
src/or/shared_random_state.h
src/test/test_shared_random.c

diff --git a/changes/bug29706_minimal b/changes/bug29706_minimal
new file mode 100644 (file)
index 0000000..9d4a433
--- /dev/null
@@ -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.
index 8438d4640473f61e19073979351a963c14684eb7..f27eccafc76c8a736d991c21bacef7aa2c37c9b0 100644 (file)
@@ -1007,7 +1007,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);
@@ -1015,7 +1015,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);
index 43a7f1d284b677cc9dafad614ed6a4666a58a3a6..cf027f2d35e16868fb4567d6853a76154cfdfaa4 100644 (file)
@@ -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 /* TOR_UNIT_TESTS */
 
index cebe772d94b4965f6500f5ed44792a71916a1595..0a3c2e119b2b3bb1a07911fcf7b669c510d57cba 100644 (file)
@@ -461,6 +461,8 @@ test_sr_setup_srv(int also_current)
          "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ",
          sizeof(srv->value));
 
+ /* sr_state_set_previous_srv() does not free() the old previous srv. */
+ state_del_previous_srv();
  sr_state_set_previous_srv(srv);
 
  if (also_current) {
@@ -470,6 +472,8 @@ test_sr_setup_srv(int also_current)
           "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN",
           sizeof(srv->value));
 
+   /* sr_state_set_previous_srv() does not free() the old current srv. */
+   state_del_current_srv();
    sr_state_set_current_srv(srv);
  }
 }