tor-commits
Threads by month
- ----- 2025 -----
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
December 2017
- 14 participants
- 2422 discussions

[tor/master] Make tor_free only evaluate its input once (at least on gcc and clang)
by nickm@torproject.org 08 Dec '17
by nickm@torproject.org 08 Dec '17
08 Dec '17
commit 1d348989b08a3d3c50dfa2600a5e5e2f61fb2b4a
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Mon Dec 4 15:18:13 2017 -0500
Make tor_free only evaluate its input once (at least on gcc and clang)
---
configure.ac | 1 -
src/common/util.h | 10 ++++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index 93b18a326..bb34e5883 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1988,7 +1988,6 @@ if test "x$enable_gcc_warnings_advisory" != "xno"; then
-Winvalid-source-encoding
-Winvalid-token-paste
-Wknr-promoted-parameter
- -Wlanguage-extension-token
-Wlarge-by-value-copy
-Wliteral-conversion
-Wliteral-range
diff --git a/src/common/util.h b/src/common/util.h
index 9ed11260d..e85be57c0 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -80,12 +80,22 @@ extern int dmalloc_free(const char *file, const int line, void *pnt,
* This is a macro. If you need a function pointer to release memory from
* tor_malloc(), use tor_free_().
*/
+#ifdef __GNUC__
+#define tor_free(p) STMT_BEGIN \
+ typeof(&(p)) tor_free__tmpvar = &(p); \
+ if (PREDICT_LIKELY((*tor_free__tmpvar)!=NULL)) { \
+ raw_free(*tor_free__tmpvar); \
+ *tor_free__tmpvar=NULL; \
+ } \
+ STMT_END
+#else
#define tor_free(p) STMT_BEGIN \
if (PREDICT_LIKELY((p)!=NULL)) { \
raw_free(p); \
(p)=NULL; \
} \
STMT_END
+#endif
#endif /* defined(USE_DMALLOC) */
#define tor_malloc(size) tor_malloc_(size DMALLOC_ARGS)
1
0

[tor/master] Add a macro to call a free_ function and clear a variable
by nickm@torproject.org 08 Dec '17
by nickm@torproject.org 08 Dec '17
08 Dec '17
commit c1bdb80aba64ac378784840d231b0db098c05474
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Nov 17 11:45:47 2017 -0500
Add a macro to call a free_ function and clear a variable
---
src/common/util.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/common/util.h b/src/common/util.h
index 6bc853da2..e11265a5d 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -109,6 +109,14 @@ extern int dmalloc_free(const char *file, const int line, void *pnt,
void tor_log_mallinfo(int severity);
+/* Helper macro: free a variable of type 'type' using type_free_, and
+ * set the variable to NULL. */
+#define FREE_AND_NULL(type, var) \
+ do { \
+ type ## _free_(var); \
+ (var) = NULL; \
+ } while (0)
+
/** Macro: yield a pointer to the field at position <b>off</b> within the
* structure <b>st</b>. Example:
* <pre>
1
0

08 Dec '17
commit b0cc9856ee560865d2668afbff20e8b77986e4ee
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Tue Nov 21 08:29:42 2017 -0500
Update free functions into macros: src/or/ part 1
This covers addressmap.h (no change needed) through confparse.h
---
src/or/channel.c | 5 +++--
src/or/channel.h | 6 ++++--
src/or/circuitbuild.c | 2 +-
src/or/circuitbuild.h | 3 ++-
src/or/circuitlist.c | 2 +-
src/or/circuitlist.h | 3 ++-
src/or/circuitmux.c | 2 +-
src/or/circuitmux.h | 3 ++-
src/or/config.c | 2 +-
src/or/config.h | 3 ++-
src/or/confparse.c | 2 +-
src/or/confparse.h | 7 ++++++-
src/test/test.c | 4 ++--
src/test/test_cell_queue.c | 4 ++--
src/test/test_circuitlist.c | 28 ++++++++++++++--------------
src/test/test_entrynodes.c | 4 ++--
src/test/test_hs_client.c | 4 ++--
src/test/test_hs_intropoint.c | 38 +++++++++++++++++++-------------------
src/test/test_hs_service.c | 16 ++++++++--------
19 files changed, 75 insertions(+), 63 deletions(-)
diff --git a/src/or/channel.c b/src/or/channel.c
index 0b5a7fde9..a9e081795 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -1,3 +1,4 @@
+
/* * Copyright (c) 2012-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
@@ -979,7 +980,7 @@ channel_init_listener(channel_listener_t *chan_l)
*/
void
-channel_free(channel_t *chan)
+channel_free_(channel_t *chan)
{
if (!chan) return;
@@ -1034,7 +1035,7 @@ channel_free(channel_t *chan)
*/
void
-channel_listener_free(channel_listener_t *chan_l)
+channel_listener_free_(channel_listener_t *chan_l)
{
if (!chan_l) return;
diff --git a/src/or/channel.h b/src/or/channel.h
index e23d70791..0ee99dcaf 100644
--- a/src/or/channel.h
+++ b/src/or/channel.h
@@ -516,8 +516,10 @@ void channel_listener_close_for_error(channel_listener_t *chan_l);
void channel_listener_closed(channel_listener_t *chan_l);
/* Free a channel */
-void channel_free(channel_t *chan);
-void channel_listener_free(channel_listener_t *chan_l);
+void channel_free_(channel_t *chan);
+#define channel_free(chan) FREE_AND_NULL(channel, (chan))
+void channel_listener_free_(channel_listener_t *chan_l);
+#define channel_listener_free(chan_l) FREE_AND_NULL(channel_listener, (chan_l))
/* State/metadata setters */
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 7f0bcc415..2b581396f 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -2729,7 +2729,7 @@ extend_info_from_node(const node_t *node, int for_direct_connect)
/** Release storage held by an extend_info_t struct. */
void
-extend_info_free(extend_info_t *info)
+extend_info_free_(extend_info_t *info)
{
if (!info)
return;
diff --git a/src/or/circuitbuild.h b/src/or/circuitbuild.h
index b8a651e05..6c3c91f83 100644
--- a/src/or/circuitbuild.h
+++ b/src/or/circuitbuild.h
@@ -58,7 +58,8 @@ extend_info_t *extend_info_new(const char *nickname,
const tor_addr_t *addr, uint16_t port);
extend_info_t *extend_info_from_node(const node_t *r, int for_direct_connect);
extend_info_t *extend_info_dup(extend_info_t *info);
-void extend_info_free(extend_info_t *info);
+void extend_info_free_(extend_info_t *info);
+#define extend_info_free(info) FREE_AND_NULL(extend_info, (info))
int extend_info_addr_is_allowed(const tor_addr_t *addr);
int extend_info_supports_tap(const extend_info_t* ei);
int extend_info_supports_ntor(const extend_info_t* ei);
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index d37d986f1..0171ed4f1 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -924,7 +924,7 @@ circuit_clear_testing_cell_stats(circuit_t *circ)
/** Deallocate space associated with circ.
*/
STATIC void
-circuit_free(circuit_t *circ)
+circuit_free_(circuit_t *circ)
{
circid_t n_circ_id = 0;
void *mem;
diff --git a/src/or/circuitlist.h b/src/or/circuitlist.h
index 5d0da15ca..ffa250b2c 100644
--- a/src/or/circuitlist.h
+++ b/src/or/circuitlist.h
@@ -81,7 +81,8 @@ MOCK_DECL(void, channel_note_destroy_not_pending,
smartlist_t *circuit_find_circuits_to_upgrade_from_guard_wait(void);
#ifdef CIRCUITLIST_PRIVATE
-STATIC void circuit_free(circuit_t *circ);
+STATIC void circuit_free_(circuit_t *circ);
+#define circuit_free(circ) FREE_AND_NULL(circuit, (circ))
STATIC size_t n_cells_in_circ_queues(const circuit_t *c);
STATIC uint32_t circuit_max_queued_data_age(const circuit_t *c, uint32_t now);
STATIC uint32_t circuit_max_queued_cell_age(const circuit_t *c, uint32_t now);
diff --git a/src/or/circuitmux.c b/src/or/circuitmux.c
index f3b8aecb1..d8408f45f 100644
--- a/src/or/circuitmux.c
+++ b/src/or/circuitmux.c
@@ -546,7 +546,7 @@ circuitmux_mark_destroyed_circids_usable(circuitmux_t *cmux, channel_t *chan)
*/
void
-circuitmux_free(circuitmux_t *cmux)
+circuitmux_free_(circuitmux_t *cmux)
{
if (!cmux) return;
diff --git a/src/or/circuitmux.h b/src/or/circuitmux.h
index 3e7496ea1..e7f345f67 100644
--- a/src/or/circuitmux.h
+++ b/src/or/circuitmux.h
@@ -104,7 +104,8 @@ void circuitmux_assert_okay(circuitmux_t *cmux);
circuitmux_t * circuitmux_alloc(void);
void circuitmux_detach_all_circuits(circuitmux_t *cmux,
smartlist_t *detached_out);
-void circuitmux_free(circuitmux_t *cmux);
+void circuitmux_free_(circuitmux_t *cmux);
+#define circuitmux_free(cmux) FREE_AND_NULL(circuitmux, (cmux))
/* Policy control */
void circuitmux_clear_policy(circuitmux_t *cmux);
diff --git a/src/or/config.c b/src/or/config.c
index fac3a36d1..b32576ccc 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -5739,7 +5739,7 @@ validate_transport_socks_arguments(const smartlist_t *args)
/** Deallocate a bridge_line_t structure. */
/* private */ void
-bridge_line_free(bridge_line_t *bridge_line)
+bridge_line_free_(bridge_line_t *bridge_line)
{
if (!bridge_line)
return;
diff --git a/src/or/config.h b/src/or/config.h
index efdd8c59b..cc8003fb3 100644
--- a/src/or/config.h
+++ b/src/or/config.h
@@ -152,7 +152,8 @@ typedef struct bridge_line_t {
transport proxy. */
} bridge_line_t;
-void bridge_line_free(bridge_line_t *bridge_line);
+void bridge_line_free_(bridge_line_t *bridge_line);
+#define bridge_line_free(line) FREE_AND_NULL(bridge_line, (line))
bridge_line_t *parse_bridge_line(const char *line);
smartlist_t *get_options_from_transport_options_line(const char *line,
const char *transport);
diff --git a/src/or/confparse.c b/src/or/confparse.c
index abae7e33d..64ed9ee6b 100644
--- a/src/or/confparse.c
+++ b/src/or/confparse.c
@@ -863,7 +863,7 @@ config_reset(const config_format_t *fmt, void *options,
/** Release storage held by <b>options</b>. */
void
-config_free(const config_format_t *fmt, void *options)
+config_free_(const config_format_t *fmt, void *options)
{
int i;
diff --git a/src/or/confparse.h b/src/or/confparse.h
index 6f0b3b325..f497f55ac 100644
--- a/src/or/confparse.h
+++ b/src/or/confparse.h
@@ -177,7 +177,12 @@ typedef struct config_format_t {
#define CAL_WARN_DEPRECATIONS (1u<<2)
void *config_new(const config_format_t *fmt);
-void config_free(const config_format_t *fmt, void *options);
+void config_free_(const config_format_t *fmt, void *options);
+#define config_free(fmt, options) do { \
+ config_free_((fmt), (options)); \
+ (options) = NULL; \
+ } while (0)
+
config_line_t *config_get_assigned_option(const config_format_t *fmt,
const void *options, const char *key,
int escape_val);
diff --git a/src/test/test.c b/src/test/test.c
index 00857c238..1c5b654df 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -345,8 +345,8 @@ test_onion_queues(void *arg)
tt_int_op(0,OP_EQ, onion_num_pending(ONION_HANDSHAKE_TYPE_NTOR));
done:
- circuit_free(TO_CIRCUIT(circ1));
- circuit_free(TO_CIRCUIT(circ2));
+ circuit_free_(TO_CIRCUIT(circ1));
+ circuit_free_(TO_CIRCUIT(circ2));
tor_free(create1);
tor_free(create2);
tor_free(onionskin);
diff --git a/src/test/test_cell_queue.c b/src/test/test_cell_queue.c
index 69e89b69b..df987f82c 100644
--- a/src/test/test_cell_queue.c
+++ b/src/test/test_cell_queue.c
@@ -130,8 +130,8 @@ test_circuit_n_cells(void *arg)
tt_int_op(n_cells_in_circ_queues(TO_CIRCUIT(origin_c)), OP_EQ, 2);
done:
- circuit_free(TO_CIRCUIT(or_c));
- circuit_free(TO_CIRCUIT(origin_c));
+ circuit_free_(TO_CIRCUIT(or_c));
+ circuit_free_(TO_CIRCUIT(origin_c));
}
struct testcase_t cell_queue_tests[] = {
diff --git a/src/test/test_circuitlist.c b/src/test/test_circuitlist.c
index f622704ec..d170009a9 100644
--- a/src/test/test_circuitlist.c
+++ b/src/test/test_circuitlist.c
@@ -141,7 +141,7 @@ test_clist_maps(void *arg)
/* Okay, now free ch2 and make sure that the circuit ID is STILL not
* usable, because we haven't declared the destroy to be nonpending */
tt_int_op(cdm.ncalls, OP_EQ, 0);
- circuit_free(TO_CIRCUIT(or_c2));
+ circuit_free_(TO_CIRCUIT(or_c2));
or_c2 = NULL; /* prevent free */
tt_int_op(cdm.ncalls, OP_EQ, 2);
memset(&cdm, 0, sizeof(cdm));
@@ -160,9 +160,9 @@ test_clist_maps(void *arg)
done:
if (or_c1)
- circuit_free(TO_CIRCUIT(or_c1));
+ circuit_free_(TO_CIRCUIT(or_c1));
if (or_c2)
- circuit_free(TO_CIRCUIT(or_c2));
+ circuit_free_(TO_CIRCUIT(or_c2));
if (ch1)
tor_free(ch1->cmux);
if (ch2)
@@ -234,11 +234,11 @@ test_rend_token_maps(void *arg)
/* Marking a circuit makes it not get returned any more */
circuit_mark_for_close(TO_CIRCUIT(c1), END_CIRC_REASON_FINISHED);
tt_ptr_op(NULL, OP_EQ, hs_circuitmap_get_rend_circ_relay_side(tok1));
- circuit_free(TO_CIRCUIT(c1));
+ circuit_free_(TO_CIRCUIT(c1));
c1 = NULL;
/* Freeing a circuit makes it not get returned any more. */
- circuit_free(TO_CIRCUIT(c2));
+ circuit_free_(TO_CIRCUIT(c2));
c2 = NULL;
tt_ptr_op(NULL, OP_EQ, hs_circuitmap_get_intro_circ_v2_relay_side(tok2));
@@ -275,15 +275,15 @@ test_rend_token_maps(void *arg)
done:
if (c1)
- circuit_free(TO_CIRCUIT(c1));
+ circuit_free_(TO_CIRCUIT(c1));
if (c2)
- circuit_free(TO_CIRCUIT(c2));
+ circuit_free_(TO_CIRCUIT(c2));
if (c3)
- circuit_free(TO_CIRCUIT(c3));
+ circuit_free_(TO_CIRCUIT(c3));
if (c4)
- circuit_free(TO_CIRCUIT(c4));
+ circuit_free_(TO_CIRCUIT(c4));
if (c5)
- circuit_free(TO_CIRCUIT(c5));
+ circuit_free_(TO_CIRCUIT(c5));
}
static void
@@ -452,10 +452,10 @@ test_hs_circuitmap_isolation(void *arg)
}
done:
- circuit_free(TO_CIRCUIT(circ1));
- circuit_free(TO_CIRCUIT(circ2));
- circuit_free(TO_CIRCUIT(circ3));
- circuit_free(TO_CIRCUIT(circ4));
+ circuit_free_(TO_CIRCUIT(circ1));
+ circuit_free_(TO_CIRCUIT(circ2));
+ circuit_free_(TO_CIRCUIT(circ3));
+ circuit_free_(TO_CIRCUIT(circ4));
}
struct testcase_t circuitlist_tests[] = {
diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c
index 43cc39488..564b992b9 100644
--- a/src/test/test_entrynodes.c
+++ b/src/test/test_entrynodes.c
@@ -2372,8 +2372,8 @@ upgrade_circuits_cleanup(const struct testcase_t *testcase, void *ptr)
// circuit_guard_state_free(data->guard2_state); // held in circ2
guard_selection_free(data->gs);
smartlist_free(data->all_origin_circuits);
- circuit_free(TO_CIRCUIT(data->circ1));
- circuit_free(TO_CIRCUIT(data->circ2));
+ circuit_free_(TO_CIRCUIT(data->circ1));
+ circuit_free_(TO_CIRCUIT(data->circ2));
tor_free(data);
return big_fake_network_cleanup(testcase, NULL);
}
diff --git a/src/test/test_hs_client.c b/src/test/test_hs_client.c
index 750920fac..6e2d956b4 100644
--- a/src/test/test_hs_client.c
+++ b/src/test/test_hs_client.c
@@ -230,7 +230,7 @@ test_e2e_rend_circuit_setup_legacy(void *arg)
connection_free_(conn);
if (or_circ)
tor_free(TO_CIRCUIT(or_circ)->n_chan);
- circuit_free(TO_CIRCUIT(or_circ));
+ circuit_free_(TO_CIRCUIT(or_circ));
}
/* Test: Ensure that setting up v3 rendezvous circuits works correctly. */
@@ -300,7 +300,7 @@ test_e2e_rend_circuit_setup(void *arg)
connection_free_(conn);
if (or_circ)
tor_free(TO_CIRCUIT(or_circ)->n_chan);
- circuit_free(TO_CIRCUIT(or_circ));
+ circuit_free_(TO_CIRCUIT(or_circ));
}
/** Test client logic for picking intro points from a descriptor. Also test how
diff --git a/src/test/test_hs_intropoint.c b/src/test/test_hs_intropoint.c
index 0cae2de7e..6a7962b21 100644
--- a/src/test/test_hs_intropoint.c
+++ b/src/test/test_hs_intropoint.c
@@ -194,7 +194,7 @@ test_establish_intro_wrong_purpose(void *arg)
tt_int_op(retval, OP_EQ, -1);
done:
- circuit_free(TO_CIRCUIT(intro_circ));
+ circuit_free_(TO_CIRCUIT(intro_circ));
}
/* Prepare a circuit for accepting an ESTABLISH_INTRO cell */
@@ -228,7 +228,7 @@ test_establish_intro_wrong_keytype(void *arg)
tt_int_op(retval, OP_EQ, -1);
done:
- circuit_free(TO_CIRCUIT(intro_circ));
+ circuit_free_(TO_CIRCUIT(intro_circ));
}
/* Send an ESTABLISH_INTRO cell with an unknown auth key type. Should fail. */
@@ -263,7 +263,7 @@ test_establish_intro_wrong_keytype2(void *arg)
tt_int_op(retval, OP_EQ, -1);
done:
- circuit_free(TO_CIRCUIT(intro_circ));
+ circuit_free_(TO_CIRCUIT(intro_circ));
}
/* Send a legit ESTABLISH_INTRO cell but with a wrong MAC. Should fail. */
@@ -333,7 +333,7 @@ test_establish_intro_wrong_mac(void *arg)
done:
trn_cell_establish_intro_free(cell);
- circuit_free(TO_CIRCUIT(intro_circ));
+ circuit_free_(TO_CIRCUIT(intro_circ));
}
/* Send a legit ESTABLISH_INTRO cell but with a wrong auth key length. Should
@@ -378,7 +378,7 @@ test_establish_intro_wrong_auth_key_len(void *arg)
done:
trn_cell_establish_intro_free(cell);
- circuit_free(TO_CIRCUIT(intro_circ));
+ circuit_free_(TO_CIRCUIT(intro_circ));
}
/* Send a legit ESTABLISH_INTRO cell but with a wrong sig length. Should
@@ -423,7 +423,7 @@ test_establish_intro_wrong_sig_len(void *arg)
done:
trn_cell_establish_intro_free(cell);
- circuit_free(TO_CIRCUIT(intro_circ));
+ circuit_free_(TO_CIRCUIT(intro_circ));
}
/* Send a legit ESTABLISH_INTRO cell but slightly change the signature. Should
@@ -460,7 +460,7 @@ test_establish_intro_wrong_sig(void *arg)
tt_int_op(retval, OP_EQ, -1);
done:
- circuit_free(TO_CIRCUIT(intro_circ));
+ circuit_free_(TO_CIRCUIT(intro_circ));
}
/* Helper function: Send a well-formed v3 ESTABLISH_INTRO cell to
@@ -629,8 +629,8 @@ test_intro_point_registration(void *arg)
done:
crypto_pk_free(legacy_auth_key);
- circuit_free(TO_CIRCUIT(intro_circ));
- circuit_free(TO_CIRCUIT(legacy_intro_circ));
+ circuit_free_(TO_CIRCUIT(intro_circ));
+ circuit_free_(TO_CIRCUIT(legacy_intro_circ));
trn_cell_establish_intro_free(establish_intro_cell);
test_circuitmap_free_all();
@@ -650,7 +650,7 @@ test_introduce1_suitable_circuit(void *arg)
circ = or_circuit_new(0, NULL);
circuit_change_purpose(TO_CIRCUIT(circ), CIRCUIT_PURPOSE_OR);
ret = circuit_is_suitable_for_introduce1(circ);
- circuit_free(TO_CIRCUIT(circ));
+ circuit_free_(TO_CIRCUIT(circ));
tt_int_op(ret, OP_EQ, 1);
}
@@ -659,7 +659,7 @@ test_introduce1_suitable_circuit(void *arg)
circ = or_circuit_new(0, NULL);
circuit_change_purpose(TO_CIRCUIT(circ), CIRCUIT_PURPOSE_INTRO_POINT);
ret = circuit_is_suitable_for_introduce1(circ);
- circuit_free(TO_CIRCUIT(circ));
+ circuit_free_(TO_CIRCUIT(circ));
tt_int_op(ret, OP_EQ, 0);
}
@@ -670,7 +670,7 @@ test_introduce1_suitable_circuit(void *arg)
/* Bogus pointer, the check is against NULL on n_chan. */
circ->base_.n_chan = (channel_t *) circ;
ret = circuit_is_suitable_for_introduce1(circ);
- circuit_free(TO_CIRCUIT(circ));
+ circuit_free_(TO_CIRCUIT(circ));
tt_int_op(ret, OP_EQ, 0);
}
@@ -681,7 +681,7 @@ test_introduce1_suitable_circuit(void *arg)
circuit_change_purpose(TO_CIRCUIT(circ), CIRCUIT_PURPOSE_OR);
circ->already_received_introduce1 = 1;
ret = circuit_is_suitable_for_introduce1(circ);
- circuit_free(TO_CIRCUIT(circ));
+ circuit_free_(TO_CIRCUIT(circ));
tt_int_op(ret, OP_EQ, 0);
}
@@ -800,7 +800,7 @@ test_received_introduce1_handling(void *arg)
circ = helper_create_intro_circuit();
ret = hs_intro_received_introduce1(circ, buf, DIGEST_LEN - 1);
tt_int_op(ret, OP_EQ, -1);
- circuit_free(TO_CIRCUIT(circ));
+ circuit_free_(TO_CIRCUIT(circ));
}
/* We have a unit test only for the suitability of a circuit to receive an
@@ -813,7 +813,7 @@ test_received_introduce1_handling(void *arg)
memset(test, 0, sizeof(test));
ret = handle_introduce1(circ, test, sizeof(test));
tor_free(circ->p_chan);
- circuit_free(TO_CIRCUIT(circ));
+ circuit_free_(TO_CIRCUIT(circ));
tt_int_op(ret, OP_EQ, -1);
}
@@ -838,8 +838,8 @@ test_received_introduce1_handling(void *arg)
memcpy(auth_key.pubkey, cell_auth_key, ED25519_PUBKEY_LEN);
hs_circuitmap_register_intro_circ_v3_relay_side(service_circ, &auth_key);
ret = hs_intro_received_introduce1(circ, request, request_len);
- circuit_free(TO_CIRCUIT(circ));
- circuit_free(TO_CIRCUIT(service_circ));
+ circuit_free_(TO_CIRCUIT(circ));
+ circuit_free_(TO_CIRCUIT(service_circ));
tt_int_op(ret, OP_EQ, 0);
}
@@ -867,8 +867,8 @@ test_received_introduce1_handling(void *arg)
memcpy(token, legacy_key_id, sizeof(token));
hs_circuitmap_register_intro_circ_v2_relay_side(service_circ, token);
ret = hs_intro_received_introduce1(circ, request, request_len);
- circuit_free(TO_CIRCUIT(circ));
- circuit_free(TO_CIRCUIT(service_circ));
+ circuit_free_(TO_CIRCUIT(circ));
+ circuit_free_(TO_CIRCUIT(service_circ));
tt_int_op(ret, OP_EQ, 0);
}
diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c
index 3084c6b95..99aa4ae7b 100644
--- a/src/test/test_hs_service.c
+++ b/src/test/test_hs_service.c
@@ -182,7 +182,7 @@ test_e2e_rend_circuit_setup(void *arg)
tt_int_op(or_circ->base_.purpose, OP_EQ, CIRCUIT_PURPOSE_S_REND_JOINED);
done:
- circuit_free(TO_CIRCUIT(or_circ));
+ circuit_free_(TO_CIRCUIT(or_circ));
}
/* Helper: Return a newly allocated and initialized origin circuit with
@@ -655,7 +655,7 @@ test_intro_circuit_opened(void *arg)
teardown_capture_of_logs();
done:
- circuit_free(TO_CIRCUIT(circ));
+ circuit_free_(TO_CIRCUIT(circ));
hs_free_all();
UNMOCK(circuit_mark_for_close_);
UNMOCK(relay_send_command_from_edge_);
@@ -730,7 +730,7 @@ test_intro_established(void *arg)
done:
if (circ)
- circuit_free(TO_CIRCUIT(circ));
+ circuit_free_(TO_CIRCUIT(circ));
hs_free_all();
UNMOCK(circuit_mark_for_close_);
}
@@ -772,7 +772,7 @@ test_rdv_circuit_opened(void *arg)
tt_int_op(TO_CIRCUIT(circ)->purpose, OP_EQ, CIRCUIT_PURPOSE_S_REND_JOINED);
done:
- circuit_free(TO_CIRCUIT(circ));
+ circuit_free_(TO_CIRCUIT(circ));
hs_free_all();
UNMOCK(circuit_mark_for_close_);
UNMOCK(relay_send_command_from_edge_);
@@ -852,7 +852,7 @@ test_introduce2(void *arg)
or_state_free(dummy_state);
dummy_state = NULL;
if (circ)
- circuit_free(TO_CIRCUIT(circ));
+ circuit_free_(TO_CIRCUIT(circ));
hs_free_all();
UNMOCK(circuit_mark_for_close_);
}
@@ -936,7 +936,7 @@ test_service_event(void *arg)
done:
hs_circuitmap_remove_circuit(TO_CIRCUIT(circ));
- circuit_free(TO_CIRCUIT(circ));
+ circuit_free_(TO_CIRCUIT(circ));
hs_free_all();
UNMOCK(circuit_mark_for_close_);
}
@@ -1490,8 +1490,8 @@ test_rendezvous1_parsing(void *arg)
* would need an extra circuit and some more stuff but it's doable. */
done:
- circuit_free(TO_CIRCUIT(service_circ));
- circuit_free(TO_CIRCUIT(client_circ));
+ circuit_free_(TO_CIRCUIT(service_circ));
+ circuit_free_(TO_CIRCUIT(client_circ));
hs_service_free(service);
hs_free_all();
UNMOCK(relay_send_command_from_edge_);
1
0

08 Dec '17
commit db024adc90069ce9961f3993aba1b7372f09d77a
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Mon Dec 4 15:09:18 2017 -0500
Switch to a safer FREE_AND_NULL implementation
This one only evaluates the input once, so it cannot mess up even if
there are side effects.
---
src/common/address.h | 2 +-
src/common/aes.h | 3 ++-
src/common/compat_libevent.h | 3 ++-
src/common/compress.h | 3 ++-
src/common/compress_lzma.h | 4 +++-
src/common/compress_zlib.h | 4 +++-
src/common/compress_zstd.h | 4 +++-
src/common/log.c | 2 +-
src/common/timers.h | 2 +-
src/common/util.h | 21 ++++++++++++++++-----
src/or/hs_service.c | 2 +-
src/or/hs_service.h | 9 ++++++---
src/or/networkstatus.h | 3 ++-
src/or/policies.h | 3 ++-
src/or/rendcache.c | 6 +++---
src/or/rendcache.h | 10 ++++++----
src/or/rendservice.c | 6 +++---
src/or/router.h | 3 ++-
src/or/routerlist.c | 2 +-
src/or/shared_random_state.c | 2 +-
src/test/test.c | 2 +-
src/test/test_dir.c | 2 +-
22 files changed, 63 insertions(+), 35 deletions(-)
diff --git a/src/common/address.h b/src/common/address.h
index 84d136d67..6f59e1c96 100644
--- a/src/common/address.h
+++ b/src/common/address.h
@@ -208,7 +208,7 @@ MOCK_DECL(int,get_interface_address6,(int severity, sa_family_t family,
tor_addr_t *addr));
void interface_address6_list_free_(smartlist_t * addrs);// XXXX
#define interface_address6_list_free(addrs) \
- FREE_AND_NULL(interface_address6_list, (addrs))
+ FREE_AND_NULL_UNMATCHED(smartlist_t, interface_address6_list_free_, (addrs))
MOCK_DECL(smartlist_t *,get_interface_address6_list,(int severity,
sa_family_t family,
int include_internal));
diff --git a/src/common/aes.h b/src/common/aes.h
index 4874f728d..c2720d29b 100644
--- a/src/common/aes.h
+++ b/src/common/aes.h
@@ -18,7 +18,8 @@ typedef struct aes_cnt_cipher aes_cnt_cipher_t;
aes_cnt_cipher_t* aes_new_cipher(const uint8_t *key, const uint8_t *iv,
int key_bits);
void aes_cipher_free_(aes_cnt_cipher_t *cipher);
-#define aes_cipher_free(cipher) FREE_AND_NULL(aes_cipher, (cipher))
+#define aes_cipher_free(cipher) \
+ FREE_AND_NULL_UNMATCHED(aes_cnt_cipher_t, aes_cipher_free_, (cipher))
void aes_crypt_inplace(aes_cnt_cipher_t *cipher, char *data, size_t len);
int evaluate_evp_for_aes(int force_value);
diff --git a/src/common/compat_libevent.h b/src/common/compat_libevent.h
index 65807315c..2c86194d0 100644
--- a/src/common/compat_libevent.h
+++ b/src/common/compat_libevent.h
@@ -20,7 +20,8 @@ void suppress_libevent_log_msg(const char *msg);
(sock),(tcp),(cb),(data));
void tor_event_free_(struct event *ev);
-#define tor_event_free(ev) FREE_AND_NULL(tor_event, (ev))
+#define tor_event_free(ev) \
+ FREE_AND_NULL_UNMATCHED(struct event, tor_event_free_, (ev))
typedef struct periodic_timer_t periodic_timer_t;
diff --git a/src/common/compress.h b/src/common/compress.h
index eee4a315d..7420f169f 100644
--- a/src/common/compress.h
+++ b/src/common/compress.h
@@ -81,7 +81,8 @@ tor_compress_output_t tor_compress_process(tor_compress_state_t *state,
const char **in, size_t *in_len,
int finish);
void tor_compress_free_(tor_compress_state_t *state);
-#define tor_compress_free(st) FREE_AND_NULL(tor_compress, (st))
+#define tor_compress_free(st) \
+ FREE_AND_NULL_UNMATCHED(tor_compress_state_t, tor_compress_free_, (st))
size_t tor_compress_state_size(const tor_compress_state_t *state);
diff --git a/src/common/compress_lzma.h b/src/common/compress_lzma.h
index 1e92fd660..986bfe9a6 100644
--- a/src/common/compress_lzma.h
+++ b/src/common/compress_lzma.h
@@ -32,7 +32,9 @@ tor_lzma_compress_process(tor_lzma_compress_state_t *state,
int finish);
void tor_lzma_compress_free_(tor_lzma_compress_state_t *state);
-#define tor_lzma_compress_free(st) FREE_AND_NULL(tor_lzma_compress, (st))
+#define tor_lzma_compress_free(st) \
+ FREE_AND_NULL_UNMATCHED(tor_lzma_compress_state_t, \
+ tor_lzma_compress_free_, (st))
size_t tor_lzma_compress_state_size(const tor_lzma_compress_state_t *state);
diff --git a/src/common/compress_zlib.h b/src/common/compress_zlib.h
index 3377e0e8d..701e2f9e8 100644
--- a/src/common/compress_zlib.h
+++ b/src/common/compress_zlib.h
@@ -32,7 +32,9 @@ tor_zlib_compress_process(tor_zlib_compress_state_t *state,
int finish);
void tor_zlib_compress_free_(tor_zlib_compress_state_t *state);
-#define tor_zlib_compress_free(st) FREE_AND_NULL(tor_zlib_compress, (st))
+#define tor_zlib_compress_free(st) \
+ FREE_AND_NULL_UNMATCHED(tor_zlib_compress_state_t, \
+ tor_zlib_compress_free_, (st))
size_t tor_zlib_compress_state_size(const tor_zlib_compress_state_t *state);
diff --git a/src/common/compress_zstd.h b/src/common/compress_zstd.h
index 9f67a9c58..3e18febb1 100644
--- a/src/common/compress_zstd.h
+++ b/src/common/compress_zstd.h
@@ -32,7 +32,9 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state,
int finish);
void tor_zstd_compress_free_(tor_zstd_compress_state_t *state);
-#define tor_zstd_compress_free(st) FREE_AND_NULL(tor_zstd_compress, (st))
+#define tor_zstd_compress_free(st) \
+ FREE_AND_NULL_UNMATCHED(tor_zstd_compress_state_t, \
+ tor_zstd_compress_free_, (st))
size_t tor_zstd_compress_state_size(const tor_zstd_compress_state_t *state);
diff --git a/src/common/log.c b/src/common/log.c
index 83098b101..d305c9ae5 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -65,7 +65,7 @@ typedef struct logfile_t {
static void log_free_(logfile_t *victim);
#define log_free(lg) \
- FREE_AND_NULL(log, (lg))
+ FREE_AND_NULL_UNMATCHED(logfile_t, log_free_, (lg))
/** Helper: map a log severity to descriptive string. */
static inline const char *
diff --git a/src/common/timers.h b/src/common/timers.h
index 6c9594d31..86e892016 100644
--- a/src/common/timers.h
+++ b/src/common/timers.h
@@ -18,7 +18,7 @@ void timer_get_cb(const tor_timer_t *t,
void timer_schedule(tor_timer_t *t, const struct timeval *delay);
void timer_disable(tor_timer_t *t);
void timer_free_(tor_timer_t *t);
-#define timer_free(t) FREE_AND_NULL(timer, (t))
+#define timer_free(t) FREE_AND_NULL_UNMATCHED(tor_timer_t, timer_free_, (t))
void timers_initialize(void);
void timers_shutdown(void);
diff --git a/src/common/util.h b/src/common/util.h
index c5bd3f0bd..9ed11260d 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -109,13 +109,24 @@ extern int dmalloc_free(const char *file, const int line, void *pnt,
void tor_log_mallinfo(int severity);
+/* Helper macro: free a variable of type 'typename' using freefn, and
+ * set the variable to NULL.
+ *
+ * We use this for legacy cases when freefn and typename don't line up
+ * perfectly.
+ */
+#define FREE_AND_NULL_UNMATCHED(typename, freefn, var) \
+ do { \
+ /* only evaluate (var) once. */ \
+ typename **tmp__free__ptr ## freefn = &(var); \
+ freefn(*tmp__free__ptr ## freefn); \
+ (*tmp__free__ptr ## freefn) = NULL; \
+ } while (0)
+
/* Helper macro: free a variable of type 'type' using type_free_, and
* set the variable to NULL. */
-#define FREE_AND_NULL(type, var) \
- do { \
- type ## _free_(var); \
- (var) = NULL; \
- } while (0)
+#define FREE_AND_NULL(type, var) \
+ FREE_AND_NULL_UNMATCHED(type ## _t, type ## _free_, (var))
/** Macro: yield a pointer to the field at position <b>off</b> within the
* structure <b>st</b>. Example:
diff --git a/src/or/hs_service.c b/src/or/hs_service.c
index e88fb2389..1f93c2d52 100644
--- a/src/or/hs_service.c
+++ b/src/or/hs_service.c
@@ -370,7 +370,7 @@ service_intro_point_free_(hs_service_intro_point_t *ip)
static void
service_intro_point_free_void(void *obj)
{
- service_intro_point_free(obj);
+ service_intro_point_free_(obj);
}
/* Return a newly allocated service intro point and fully initialized from the
diff --git a/src/or/hs_service.h b/src/or/hs_service.h
index b75903016..f933ba6ab 100644
--- a/src/or/hs_service.h
+++ b/src/or/hs_service.h
@@ -295,8 +295,9 @@ STATIC hs_service_intro_point_t *service_intro_point_new(
const extend_info_t *ei,
unsigned int is_legacy);
STATIC void service_intro_point_free_(hs_service_intro_point_t *ip);
-#define service_intro_point_free(ip) \
- FREE_AND_NULL(service_intro_point, (ip))
+#define service_intro_point_free(ip) \
+ FREE_AND_NULL_UNMATCHED(hs_service_intro_point_t, \
+ service_intro_point_free_, (ip))
STATIC void service_intro_point_add(digest256map_t *map,
hs_service_intro_point_t *ip);
STATIC void service_intro_point_remove(const hs_service_t *service,
@@ -330,7 +331,9 @@ STATIC char *
encode_desc_rev_counter_for_state(const hs_service_descriptor_t *desc);
STATIC void service_descriptor_free_(hs_service_descriptor_t *desc);
-#define service_descriptor_free(d) FREE_AND_NULL(service_descriptor, (d))
+#define service_descriptor_free(d) \
+ FREE_AND_NULL_UNMATCHED(hs_service_descriptor_t, \
+ service_descriptor_free_, (d))
STATIC uint64_t
check_state_line_for_service_rev_counter(const char *state_line,
diff --git a/src/or/networkstatus.h b/src/or/networkstatus.h
index f62b5d240..37350bb1b 100644
--- a/src/or/networkstatus.h
+++ b/src/or/networkstatus.h
@@ -21,7 +21,8 @@ int router_reload_consensus_networkstatus(void);
void routerstatus_free_(routerstatus_t *rs);
#define routerstatus_free(rs) FREE_AND_NULL(routerstatus, (rs))
void networkstatus_vote_free_(networkstatus_t *ns);
-#define networkstatus_vote_free(ns) FREE_AND_NULL(networkstatus_vote, (ns))
+#define networkstatus_vote_free(ns) \
+ FREE_AND_NULL_UNMATCHED(networkstatus_t, networkstatus_vote_free_, (ns))
networkstatus_voter_info_t *networkstatus_get_voter_by_id(
networkstatus_t *vote,
const char *identity);
diff --git a/src/or/policies.h b/src/or/policies.h
index 062f33018..451a7a7f3 100644
--- a/src/or/policies.h
+++ b/src/or/policies.h
@@ -116,7 +116,8 @@ int policy_write_item(char *buf, size_t buflen, const addr_policy_t *item,
int format_for_desc);
void addr_policy_list_free_(smartlist_t *p);
-#define addr_policy_list_free(lst) FREE_AND_NULL(addr_policy_list, (lst))
+#define addr_policy_list_free(lst) \
+ FREE_AND_NULL_UNMATCHED(smartlist_t, addr_policy_list_free_, (lst))
void addr_policy_free_(addr_policy_t *p);
#define addr_policy_free(p) FREE_AND_NULL(addr_policy, (p))
void policies_free_all(void);
diff --git a/src/or/rendcache.c b/src/or/rendcache.c
index fa454321d..6f56df671 100644
--- a/src/or/rendcache.c
+++ b/src/or/rendcache.c
@@ -131,7 +131,7 @@ rend_cache_failure_intro_entry_free_(rend_cache_failure_intro_t *entry)
static void
rend_cache_failure_intro_entry_free_void(void *entry)
{
- rend_cache_failure_intro_entry_free(entry);
+ rend_cache_failure_intro_entry_free_(entry);
}
/** Allocate a rend cache failure intro object and return it. <b>failure</b>
@@ -165,7 +165,7 @@ rend_cache_failure_entry_free_(rend_cache_failure_t *entry)
STATIC void
rend_cache_failure_entry_free_void(void *entry)
{
- rend_cache_failure_entry_free(entry);
+ rend_cache_failure_entry_free_(entry);
}
/** Allocate a rend cache failure object and return it. This function can
@@ -219,7 +219,7 @@ rend_cache_entry_free_(rend_cache_entry_t *e)
static void
rend_cache_entry_free_void(void *p)
{
- rend_cache_entry_free(p);
+ rend_cache_entry_free_(p);
}
/** Free all storage held by the service descriptor cache. */
diff --git a/src/or/rendcache.h b/src/or/rendcache.h
index 66b48e032..c1e9207a9 100644
--- a/src/or/rendcache.h
+++ b/src/or/rendcache.h
@@ -94,11 +94,13 @@ STATIC void rend_cache_entry_free_(rend_cache_entry_t *e);
#define rend_cache_entry_free(e) FREE_AND_NULL(rend_cache_entry, (e))
STATIC void rend_cache_failure_intro_entry_free_(rend_cache_failure_intro_t
*entry);
-#define rend_cache_failure_intro_entry_free(e) \
- FREE_AND_NULL(rend_cache_failure_intro_entry, (e))
+#define rend_cache_failure_intro_entry_free(e) \
+ FREE_AND_NULL_UNMATCHED(rend_cache_failure_intro_t, \
+ rend_cache_failure_intro_entry_free_, (e))
STATIC void rend_cache_failure_entry_free_(rend_cache_failure_t *entry);
-#define rend_cache_failure_entry_free(e) \
- FREE_AND_NULL(rend_cache_failure_entry, (e))
+#define rend_cache_failure_entry_free(e) \
+ FREE_AND_NULL_UNMATCHED(rend_cache_failure_t, \
+ rend_cache_failure_entry_free_, (e))
STATIC int cache_failure_intro_lookup(const uint8_t *identity,
const char *service_id,
rend_cache_failure_intro_t
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index 568afe79b..3e318f73f 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -174,7 +174,7 @@ rend_authorized_client_free_(rend_authorized_client_t *client)
static void
rend_authorized_client_strmap_item_free(void *authorized_client)
{
- rend_authorized_client_free(authorized_client);
+ rend_authorized_client_free_(authorized_client);
}
/** Release the storage held by <b>service</b>.
@@ -3726,7 +3726,7 @@ upload_service_descriptor(rend_service_t *service)
}
/* Free memory for descriptors. */
for (i = 0; i < smartlist_len(descs); i++)
- rend_encoded_v2_service_descriptor_free(smartlist_get(descs, i));
+ rend_encoded_v2_service_descriptor_free_(smartlist_get(descs, i));
smartlist_clear(descs);
/* Update next upload time. */
if (seconds_valid - REND_TIME_PERIOD_OVERLAPPING_V2_DESCS
@@ -3757,7 +3757,7 @@ upload_service_descriptor(rend_service_t *service)
}
/* Free memory for descriptors. */
for (i = 0; i < smartlist_len(descs); i++)
- rend_encoded_v2_service_descriptor_free(smartlist_get(descs, i));
+ rend_encoded_v2_service_descriptor_free_(smartlist_get(descs, i));
smartlist_clear(descs);
}
}
diff --git a/src/or/router.h b/src/or/router.h
index cd953da7a..e282b9975 100644
--- a/src/or/router.h
+++ b/src/or/router.h
@@ -37,7 +37,8 @@ int get_onion_key_grace_period(void);
di_digest256_map_t *construct_ntor_key_map(void);
void ntor_key_map_free_(di_digest256_map_t *map);
-#define ntor_key_map_free(map) FREE_AND_NULL(ntor_key_map, (map))
+#define ntor_key_map_free(map) \
+ FREE_AND_NULL_UNMATCHED(di_digest256_map_t, ntor_key_map_free_, (map))
int router_initialize_tls_context(void);
int init_keys(void);
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 877479969..0236761eb 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -3268,7 +3268,7 @@ signed_descriptor_from_routerinfo(routerinfo_t *ri)
static void
extrainfo_free_void(void *e)
{
- extrainfo_free(e);
+ extrainfo_free_(e);
}
/** Free all storage held by a routerlist <b>rl</b>. */
diff --git a/src/or/shared_random_state.c b/src/or/shared_random_state.c
index ae904cfda..8c5a497bb 100644
--- a/src/or/shared_random_state.c
+++ b/src/or/shared_random_state.c
@@ -271,7 +271,7 @@ commit_add_to_state(sr_commit_t *commit, sr_state_t *state)
static void
commit_free_(void *p)
{
- sr_commit_free(p);
+ sr_commit_free_(p);
}
/* Free a state that was allocated with state_new(). */
diff --git a/src/test/test.c b/src/test/test.c
index 1c5b654df..c08967c02 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -616,7 +616,7 @@ test_rend_fns(void *arg)
done:
if (descs) {
for (i = 0; i < smartlist_len(descs); i++)
- rend_encoded_v2_service_descriptor_free(smartlist_get(descs, i));
+ rend_encoded_v2_service_descriptor_free_(smartlist_get(descs, i));
smartlist_free(descs);
}
if (parsed)
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index 4cab307ce..35e4fb44c 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -567,7 +567,7 @@ test_dir_routerinfo_parsing(void *arg)
static void
routerinfo_free_wrapper_(void *arg)
{
- routerinfo_free(arg);
+ routerinfo_free_(arg);
}
static void
1
0

[tor/master] Make all the crypto free() functions macros that clear their targets
by nickm@torproject.org 08 Dec '17
by nickm@torproject.org 08 Dec '17
08 Dec '17
commit 2f086888b14be3998421b29bfc81d037b8073202
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Nov 17 11:55:52 2017 -0500
Make all the crypto free() functions macros that clear their targets
---
src/common/crypto.c | 10 +++++-----
src/common/crypto.h | 16 +++++++++++-----
src/common/crypto_ed25519.c | 2 +-
src/common/crypto_ed25519.h | 4 +++-
src/common/tortls.c | 4 ++--
src/common/tortls.h | 6 ++++--
6 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 6fe3c661c..ffa2b7c1c 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -529,7 +529,7 @@ crypto_pk_new,(void))
* are released, free the key.
*/
void
-crypto_pk_free(crypto_pk_t *env)
+crypto_pk_free_(crypto_pk_t *env)
{
if (!env)
return;
@@ -592,7 +592,7 @@ crypto_cipher_new(const char *key)
/** Free a symmetric cipher.
*/
void
-crypto_cipher_free(crypto_cipher_t *env)
+crypto_cipher_free_(crypto_cipher_t *env)
{
if (!env)
return;
@@ -1967,7 +1967,7 @@ crypto_digest512_new(digest_algorithm_t algorithm)
/** Deallocate a digest object.
*/
void
-crypto_digest_free(crypto_digest_t *digest)
+crypto_digest_free_(crypto_digest_t *digest)
{
if (!digest)
return;
@@ -2214,7 +2214,7 @@ crypto_xof_squeeze_bytes(crypto_xof_t *xof, uint8_t *out, size_t len)
/** Cleanse and deallocate a XOF object. */
void
-crypto_xof_free(crypto_xof_t *xof)
+crypto_xof_free_(crypto_xof_t *xof)
{
if (!xof)
return;
@@ -2767,7 +2767,7 @@ crypto_expand_key_material_rfc5869_sha256(
/** Free a DH key exchange object.
*/
void
-crypto_dh_free(crypto_dh_t *dh)
+crypto_dh_free_(crypto_dh_t *dh)
{
if (!dh)
return;
diff --git a/src/common/crypto.h b/src/common/crypto.h
index f9aeeee2c..f1061467d 100644
--- a/src/common/crypto.h
+++ b/src/common/crypto.h
@@ -19,6 +19,7 @@
#include "torint.h"
#include "testsupport.h"
#include "compat.h"
+#include "util.h"
#include <openssl/engine.h>
#include "keccak-tiny/keccak-tiny.h"
@@ -146,7 +147,8 @@ int crypto_global_cleanup(void);
/* environment setup */
MOCK_DECL(crypto_pk_t *,crypto_pk_new,(void));
-void crypto_pk_free(crypto_pk_t *env);
+void crypto_pk_free_(crypto_pk_t *env);
+#define crypto_pk_free(pk) FREE_AND_NULL(crypto_pk, (pk))
void crypto_set_tls_dh_prime(void);
crypto_cipher_t *crypto_cipher_new(const char *key);
@@ -155,7 +157,8 @@ crypto_cipher_t *crypto_cipher_new_with_iv(const char *key, const char *iv);
crypto_cipher_t *crypto_cipher_new_with_iv_and_bits(const uint8_t *key,
const uint8_t *iv,
int bits);
-void crypto_cipher_free(crypto_cipher_t *env);
+void crypto_cipher_free_(crypto_cipher_t *env);
+#define crypto_cipher_free(c) FREE_AND_NULL(crypto_cipher, (c))
/* public key crypto */
MOCK_DECL(int, crypto_pk_generate_key_with_bits,(crypto_pk_t *env, int bits));
@@ -258,7 +261,8 @@ int crypto_digest_algorithm_parse_name(const char *name);
crypto_digest_t *crypto_digest_new(void);
crypto_digest_t *crypto_digest256_new(digest_algorithm_t algorithm);
crypto_digest_t *crypto_digest512_new(digest_algorithm_t algorithm);
-void crypto_digest_free(crypto_digest_t *digest);
+void crypto_digest_free_(crypto_digest_t *digest);
+#define crypto_digest_free(d) FREE_AND_NULL(crypto_digest, (d))
void crypto_digest_add_bytes(crypto_digest_t *digest, const char *data,
size_t len);
void crypto_digest_get_digest(crypto_digest_t *digest,
@@ -276,7 +280,8 @@ void crypto_mac_sha3_256(uint8_t *mac_out, size_t len_out,
crypto_xof_t *crypto_xof_new(void);
void crypto_xof_add_bytes(crypto_xof_t *xof, const uint8_t *data, size_t len);
void crypto_xof_squeeze_bytes(crypto_xof_t *xof, uint8_t *out, size_t len);
-void crypto_xof_free(crypto_xof_t *xof);
+void crypto_xof_free_(crypto_xof_t *xof);
+#define crypto_xof_free(xof) FREE_AND_NULL(crypto_xof, (xof))
/* Key negotiation */
#define DH_TYPE_CIRCUIT 1
@@ -291,7 +296,8 @@ int crypto_dh_get_public(crypto_dh_t *dh, char *pubkey_out,
ssize_t crypto_dh_compute_secret(int severity, crypto_dh_t *dh,
const char *pubkey, size_t pubkey_len,
char *secret_out, size_t secret_out_len);
-void crypto_dh_free(crypto_dh_t *dh);
+void crypto_dh_free_(crypto_dh_t *dh);
+#define crypto_dh_free(dh) FREE_AND_NULL(crypto_dh, (dh))
int crypto_expand_key_material_TAP(const uint8_t *key_in,
size_t key_in_len,
diff --git a/src/common/crypto_ed25519.c b/src/common/crypto_ed25519.c
index 94b23e31b..26523e312 100644
--- a/src/common/crypto_ed25519.c
+++ b/src/common/crypto_ed25519.c
@@ -622,7 +622,7 @@ ed25519_pubkey_read_from_file(ed25519_public_key_t *pubkey_out,
/** Release all storage held for <b>kp</b>. */
void
-ed25519_keypair_free(ed25519_keypair_t *kp)
+ed25519_keypair_free_(ed25519_keypair_t *kp)
{
if (! kp)
return;
diff --git a/src/common/crypto_ed25519.h b/src/common/crypto_ed25519.h
index 8d13a487d..64ccc470e 100644
--- a/src/common/crypto_ed25519.h
+++ b/src/common/crypto_ed25519.h
@@ -7,6 +7,7 @@
#include "testsupport.h"
#include "torint.h"
#include "crypto_curve25519.h"
+#include "util.h"
#define ED25519_PUBKEY_LEN 32
#define ED25519_SECKEY_LEN 64
@@ -117,7 +118,8 @@ int ed25519_pubkey_read_from_file(ed25519_public_key_t *pubkey_out,
char **tag_out,
const char *filename);
-void ed25519_keypair_free(ed25519_keypair_t *kp);
+void ed25519_keypair_free_(ed25519_keypair_t *kp);
+#define ed25519_keypair_free(kp) FREE_AND_NULL(ed25519_keypair, (kp))
int ed25519_pubkey_eq(const ed25519_public_key_t *key1,
const ed25519_public_key_t *key2);
diff --git a/src/common/tortls.c b/src/common/tortls.c
index 197c5e8d3..407603248 100644
--- a/src/common/tortls.c
+++ b/src/common/tortls.c
@@ -644,7 +644,7 @@ static const char CLIENT_CIPHER_LIST[] =
/** Free all storage held in <b>cert</b> */
void
-tor_x509_cert_free(tor_x509_cert_t *cert)
+tor_x509_cert_free_(tor_x509_cert_t *cert)
{
if (! cert)
return;
@@ -1792,7 +1792,7 @@ tor_tls_is_server(tor_tls_t *tls)
* underlying file descriptor.
*/
void
-tor_tls_free(tor_tls_t *tls)
+tor_tls_free_(tor_tls_t *tls)
{
if (!tls)
return;
diff --git a/src/common/tortls.h b/src/common/tortls.h
index 6145f7dbc..b293ce20e 100644
--- a/src/common/tortls.h
+++ b/src/common/tortls.h
@@ -216,7 +216,8 @@ void tor_tls_set_renegotiate_callback(tor_tls_t *tls,
void (*cb)(tor_tls_t *, void *arg),
void *arg);
int tor_tls_is_server(tor_tls_t *tls);
-void tor_tls_free(tor_tls_t *tls);
+void tor_tls_free_(tor_tls_t *tls);
+#define tor_tls_free(tls) FREE_AND_NULL(tor_tls, (tls))
int tor_tls_peer_has_cert(tor_tls_t *tls);
MOCK_DECL(tor_x509_cert_t *,tor_tls_get_peer_cert,(tor_tls_t *tls));
MOCK_DECL(tor_x509_cert_t *,tor_tls_get_own_cert,(tor_tls_t *tls));
@@ -263,7 +264,8 @@ void check_no_tls_errors_(const char *fname, int line);
void tor_tls_log_one_error(tor_tls_t *tls, unsigned long err,
int severity, int domain, const char *doing);
-void tor_x509_cert_free(tor_x509_cert_t *cert);
+void tor_x509_cert_free_(tor_x509_cert_t *cert);
+#define tor_x509_cert_free(c) FREE_AND_NULL(tor_x509_cert, (c))
tor_x509_cert_t *tor_x509_cert_decode(const uint8_t *certificate,
size_t certificate_len);
void tor_x509_cert_get_der(const tor_x509_cert_t *cert,
1
0

08 Dec '17
commit 17dcce3fe11bfea9c7c46d2b9fd5baeb63ebe1e2
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Thu Dec 7 10:52:55 2017 -0500
Fix wide lines introduced by previous patch.
---
src/common/compat_libevent.h | 3 ++-
src/common/crypto.h | 9 ++++++---
src/common/crypto_ed25519.h | 3 ++-
src/common/storagedir.h | 3 ++-
src/common/tortls.h | 3 ++-
src/or/channel.h | 3 ++-
src/or/circuitbuild.h | 3 ++-
src/or/circuitmux.h | 3 ++-
src/or/config.h | 3 ++-
src/or/connection.h | 3 ++-
src/or/conscache.h | 6 ++++--
src/or/dircollate.h | 3 ++-
src/or/directory.h | 3 ++-
src/or/dirserv.h | 3 ++-
src/or/entrynodes.h | 8 +++++---
src/or/hs_common.h | 3 ++-
src/or/hs_descriptor.h | 6 ++++--
src/or/hs_ident.h | 9 ++++++---
src/or/networkstatus.h | 9 ++++++---
src/or/onion.h | 3 ++-
src/or/policies.h | 6 ++++--
src/or/proto_socks.h | 3 ++-
src/or/protover.h | 3 ++-
src/or/relay.h | 6 ++++--
src/or/rendcache.h | 3 ++-
src/or/rendcommon.h | 9 ++++++---
src/or/rendservice.h | 9 ++++++---
src/or/replaycache.h | 3 ++-
src/or/routerlist.h | 6 ++++--
29 files changed, 91 insertions(+), 46 deletions(-)
diff --git a/src/common/compat_libevent.h b/src/common/compat_libevent.h
index 086899ad1..0cdb73fbb 100644
--- a/src/common/compat_libevent.h
+++ b/src/common/compat_libevent.h
@@ -30,7 +30,8 @@ periodic_timer_t *periodic_timer_new(struct event_base *base,
void (*cb)(periodic_timer_t *timer, void *data),
void *data);
void periodic_timer_free_(periodic_timer_t *);
-#define periodic_timer_free(t) FREE_AND_NULL(periodic_timer_t, periodic_timer_free_, (t))
+#define periodic_timer_free(t) \
+ FREE_AND_NULL(periodic_timer_t, periodic_timer_free_, (t))
#define tor_event_base_loopexit event_base_loopexit
#define tor_event_base_loopbreak event_base_loopbreak
diff --git a/src/common/crypto.h b/src/common/crypto.h
index 30023bad9..eca115fa7 100644
--- a/src/common/crypto.h
+++ b/src/common/crypto.h
@@ -158,7 +158,8 @@ crypto_cipher_t *crypto_cipher_new_with_iv_and_bits(const uint8_t *key,
const uint8_t *iv,
int bits);
void crypto_cipher_free_(crypto_cipher_t *env);
-#define crypto_cipher_free(c) FREE_AND_NULL(crypto_cipher_t, crypto_cipher_free_, (c))
+#define crypto_cipher_free(c) \
+ FREE_AND_NULL(crypto_cipher_t, crypto_cipher_free_, (c))
/* public key crypto */
MOCK_DECL(int, crypto_pk_generate_key_with_bits,(crypto_pk_t *env, int bits));
@@ -262,7 +263,8 @@ crypto_digest_t *crypto_digest_new(void);
crypto_digest_t *crypto_digest256_new(digest_algorithm_t algorithm);
crypto_digest_t *crypto_digest512_new(digest_algorithm_t algorithm);
void crypto_digest_free_(crypto_digest_t *digest);
-#define crypto_digest_free(d) FREE_AND_NULL(crypto_digest_t, crypto_digest_free_, (d))
+#define crypto_digest_free(d) \
+ FREE_AND_NULL(crypto_digest_t, crypto_digest_free_, (d))
void crypto_digest_add_bytes(crypto_digest_t *digest, const char *data,
size_t len);
void crypto_digest_get_digest(crypto_digest_t *digest,
@@ -281,7 +283,8 @@ crypto_xof_t *crypto_xof_new(void);
void crypto_xof_add_bytes(crypto_xof_t *xof, const uint8_t *data, size_t len);
void crypto_xof_squeeze_bytes(crypto_xof_t *xof, uint8_t *out, size_t len);
void crypto_xof_free_(crypto_xof_t *xof);
-#define crypto_xof_free(xof) FREE_AND_NULL(crypto_xof_t, crypto_xof_free_, (xof))
+#define crypto_xof_free(xof) \
+ FREE_AND_NULL(crypto_xof_t, crypto_xof_free_, (xof))
/* Key negotiation */
#define DH_TYPE_CIRCUIT 1
diff --git a/src/common/crypto_ed25519.h b/src/common/crypto_ed25519.h
index c05f5dfa9..74269ccff 100644
--- a/src/common/crypto_ed25519.h
+++ b/src/common/crypto_ed25519.h
@@ -119,7 +119,8 @@ int ed25519_pubkey_read_from_file(ed25519_public_key_t *pubkey_out,
const char *filename);
void ed25519_keypair_free_(ed25519_keypair_t *kp);
-#define ed25519_keypair_free(kp) FREE_AND_NULL(ed25519_keypair_t, ed25519_keypair_free_, (kp))
+#define ed25519_keypair_free(kp) \
+ FREE_AND_NULL(ed25519_keypair_t, ed25519_keypair_free_, (kp))
int ed25519_pubkey_eq(const ed25519_public_key_t *key1,
const ed25519_public_key_t *key2);
diff --git a/src/common/storagedir.h b/src/common/storagedir.h
index 0ddb65542..d99bd7ec5 100644
--- a/src/common/storagedir.h
+++ b/src/common/storagedir.h
@@ -10,7 +10,8 @@ struct sandbox_cfg_elem;
storage_dir_t * storage_dir_new(const char *dirname, int n_files);
void storage_dir_free_(storage_dir_t *d);
-#define storage_dir_free(d) FREE_AND_NULL(storage_dir_t, storage_dir_free_, (d))
+#define storage_dir_free(d) \
+ FREE_AND_NULL(storage_dir_t, storage_dir_free_, (d))
int storage_dir_register_with_sandbox(storage_dir_t *d,
struct sandbox_cfg_elem **cfg);
diff --git a/src/common/tortls.h b/src/common/tortls.h
index df8597db0..1dbf0b332 100644
--- a/src/common/tortls.h
+++ b/src/common/tortls.h
@@ -265,7 +265,8 @@ void tor_tls_log_one_error(tor_tls_t *tls, unsigned long err,
int severity, int domain, const char *doing);
void tor_x509_cert_free_(tor_x509_cert_t *cert);
-#define tor_x509_cert_free(c) FREE_AND_NULL(tor_x509_cert_t, tor_x509_cert_free_, (c))
+#define tor_x509_cert_free(c) \
+ FREE_AND_NULL(tor_x509_cert_t, tor_x509_cert_free_, (c))
tor_x509_cert_t *tor_x509_cert_decode(const uint8_t *certificate,
size_t certificate_len);
void tor_x509_cert_get_der(const tor_x509_cert_t *cert,
diff --git a/src/or/channel.h b/src/or/channel.h
index 1ff226d37..9c631c15a 100644
--- a/src/or/channel.h
+++ b/src/or/channel.h
@@ -519,7 +519,8 @@ void channel_listener_closed(channel_listener_t *chan_l);
void channel_free_(channel_t *chan);
#define channel_free(chan) FREE_AND_NULL(channel_t, channel_free_, (chan))
void channel_listener_free_(channel_listener_t *chan_l);
-#define channel_listener_free(chan_l) FREE_AND_NULL(channel_listener_t, channel_listener_free_, (chan_l))
+#define channel_listener_free(chan_l) \
+ FREE_AND_NULL(channel_listener_t, channel_listener_free_, (chan_l))
/* State/metadata setters */
diff --git a/src/or/circuitbuild.h b/src/or/circuitbuild.h
index 68c6d9ea7..9b5fcc71e 100644
--- a/src/or/circuitbuild.h
+++ b/src/or/circuitbuild.h
@@ -59,7 +59,8 @@ extend_info_t *extend_info_new(const char *nickname,
extend_info_t *extend_info_from_node(const node_t *r, int for_direct_connect);
extend_info_t *extend_info_dup(extend_info_t *info);
void extend_info_free_(extend_info_t *info);
-#define extend_info_free(info) FREE_AND_NULL(extend_info_t, extend_info_free_, (info))
+#define extend_info_free(info) \
+ FREE_AND_NULL(extend_info_t, extend_info_free_, (info))
int extend_info_addr_is_allowed(const tor_addr_t *addr);
int extend_info_supports_tap(const extend_info_t* ei);
int extend_info_supports_ntor(const extend_info_t* ei);
diff --git a/src/or/circuitmux.h b/src/or/circuitmux.h
index 689decee8..255822946 100644
--- a/src/or/circuitmux.h
+++ b/src/or/circuitmux.h
@@ -105,7 +105,8 @@ circuitmux_t * circuitmux_alloc(void);
void circuitmux_detach_all_circuits(circuitmux_t *cmux,
smartlist_t *detached_out);
void circuitmux_free_(circuitmux_t *cmux);
-#define circuitmux_free(cmux) FREE_AND_NULL(circuitmux_t, circuitmux_free_, (cmux))
+#define circuitmux_free(cmux) \
+ FREE_AND_NULL(circuitmux_t, circuitmux_free_, (cmux))
/* Policy control */
void circuitmux_clear_policy(circuitmux_t *cmux);
diff --git a/src/or/config.h b/src/or/config.h
index c591a8e54..8c9796b4c 100644
--- a/src/or/config.h
+++ b/src/or/config.h
@@ -153,7 +153,8 @@ typedef struct bridge_line_t {
} bridge_line_t;
void bridge_line_free_(bridge_line_t *bridge_line);
-#define bridge_line_free(line) FREE_AND_NULL(bridge_line_t, bridge_line_free_, (line))
+#define bridge_line_free(line) \
+ FREE_AND_NULL(bridge_line_t, bridge_line_free_, (line))
bridge_line_t *parse_bridge_line(const char *line);
smartlist_t *get_options_from_transport_options_line(const char *line,
const char *transport);
diff --git a/src/or/connection.h b/src/or/connection.h
index 9ba1606d6..6bc5a7cfd 100644
--- a/src/or/connection.h
+++ b/src/or/connection.h
@@ -30,7 +30,8 @@ int connection_init_accepted_conn(connection_t *conn,
const listener_connection_t *listener);
void connection_link_connections(connection_t *conn_a, connection_t *conn_b);
MOCK_DECL(void,connection_free_,(connection_t *conn));
-#define connection_free(conn) FREE_AND_NULL(connection_t, connection_free_, (conn))
+#define connection_free(conn) \
+ FREE_AND_NULL(connection_t, connection_free_, (conn))
void connection_free_all(void);
void connection_about_to_close_connection(connection_t *conn);
void connection_close_immediate(connection_t *conn);
diff --git a/src/or/conscache.h b/src/or/conscache.h
index 501917bd0..08a5c5a37 100644
--- a/src/or/conscache.h
+++ b/src/or/conscache.h
@@ -11,11 +11,13 @@ typedef struct consensus_cache_t consensus_cache_t;
HANDLE_DECL(consensus_cache_entry, consensus_cache_entry_t, )
#define consensus_cache_entry_handle_free(h) \
- FREE_AND_NULL(consensus_cache_entry_handle_t, consensus_cache_entry_handle_free_, (h))
+ FREE_AND_NULL(consensus_cache_entry_handle_t, \
+ consensus_cache_entry_handle_free_, (h))
consensus_cache_t *consensus_cache_open(const char *subdir, int max_entries);
void consensus_cache_free_(consensus_cache_t *cache);
-#define consensus_cache_free(cache) FREE_AND_NULL(consensus_cache_t, consensus_cache_free_, (cache))
+#define consensus_cache_free(cache) \
+ FREE_AND_NULL(consensus_cache_t, consensus_cache_free_, (cache))
struct sandbox_cfg_elem;
int consensus_cache_may_overallocate(consensus_cache_t *cache);
int consensus_cache_register_with_sandbox(consensus_cache_t *cache,
diff --git a/src/or/dircollate.h b/src/or/dircollate.h
index f165bdfaf..0584b2fe0 100644
--- a/src/or/dircollate.h
+++ b/src/or/dircollate.h
@@ -19,7 +19,8 @@ typedef struct dircollator_s dircollator_t;
dircollator_t *dircollator_new(int n_votes, int n_authorities);
void dircollator_free_(dircollator_t *obj);
-#define dircollator_free(c) FREE_AND_NULL(dircollator_t, dircollator_free_, (c))
+#define dircollator_free(c) \
+ FREE_AND_NULL(dircollator_t, dircollator_free_, (c))
void dircollator_add_vote(dircollator_t *dc, networkstatus_t *v);
void dircollator_collate(dircollator_t *dc, int consensus_method);
diff --git a/src/or/directory.h b/src/or/directory.h
index 08ed5024d..edf75ffe1 100644
--- a/src/or/directory.h
+++ b/src/or/directory.h
@@ -52,7 +52,8 @@ int directory_must_use_begindir(const or_options_t *options);
typedef struct directory_request_t directory_request_t;
directory_request_t *directory_request_new(uint8_t dir_purpose);
void directory_request_free_(directory_request_t *req);
-#define directory_request_free(req) FREE_AND_NULL(directory_request_t, directory_request_free_, (req))
+#define directory_request_free(req) \
+ FREE_AND_NULL(directory_request_t, directory_request_free_, (req))
void directory_request_set_or_addr_port(directory_request_t *req,
const tor_addr_port_t *p);
void directory_request_set_dir_addr_port(directory_request_t *req,
diff --git a/src/or/dirserv.h b/src/or/dirserv.h
index 7c5006b18..fa9fe9501 100644
--- a/src/or/dirserv.h
+++ b/src/or/dirserv.h
@@ -196,7 +196,8 @@ spooled_resource_t *spooled_resource_new(dir_spool_source_t source,
spooled_resource_t *spooled_resource_new_from_cache_entry(
struct consensus_cache_entry_t *entry);
void spooled_resource_free_(spooled_resource_t *spooled);
-#define spooled_resource_free(sp) FREE_AND_NULL(spooled_resource_t, spooled_resource_free_, (sp))
+#define spooled_resource_free(sp) \
+ FREE_AND_NULL(spooled_resource_t, spooled_resource_free_, (sp))
void dirserv_spool_remove_missing_and_guess_size(dir_connection_t *conn,
time_t cutoff,
int compression,
diff --git a/src/or/entrynodes.h b/src/or/entrynodes.h
index 32fcfeadf..f2c8d35bf 100644
--- a/src/or/entrynodes.h
+++ b/src/or/entrynodes.h
@@ -487,7 +487,8 @@ STATIC guard_selection_t *guard_selection_new(const char *name,
STATIC guard_selection_t *get_guard_selection_by_name(
const char *name, guard_selection_type_t type, int create_if_absent);
STATIC void guard_selection_free_(guard_selection_t *gs);
-#define guard_selection_free(gs) FREE_AND_NULL(guard_selection_t, guard_selection_free_, (gs))
+#define guard_selection_free(gs) \
+ FREE_AND_NULL(guard_selection_t, guard_selection_free_, (gs))
MOCK_DECL(STATIC int, entry_guard_is_listed,
(guard_selection_t *gs, const entry_guard_t *guard));
STATIC const char *choose_guard_selection(const or_options_t *options,
@@ -572,8 +573,9 @@ STATIC entry_guard_restriction_t *guard_create_exit_restriction(
STATIC entry_guard_restriction_t *guard_create_dirserver_md_restriction(void);
STATIC void entry_guard_restriction_free_(entry_guard_restriction_t *rst);
-#define entry_guard_restriction_free(rst) \
- FREE_AND_NULL(entry_guard_restriction_t, entry_guard_restriction_free_, (rst))
+#define entry_guard_restriction_free(rst) \
+ FREE_AND_NULL(entry_guard_restriction_t, \
+ entry_guard_restriction_free_, (rst))
#endif /* defined(ENTRYNODES_PRIVATE) */
diff --git a/src/or/hs_common.h b/src/or/hs_common.h
index 10b056787..299d338f4 100644
--- a/src/or/hs_common.h
+++ b/src/or/hs_common.h
@@ -182,7 +182,8 @@ void hs_build_blinded_keypair(const ed25519_keypair_t *kp,
int hs_service_requires_uptime_circ(const smartlist_t *ports);
void rend_data_free_(rend_data_t *data);
-#define rend_data_free(data) FREE_AND_NULL(rend_data_t, rend_data_free_, (data))
+#define rend_data_free(data) \
+ FREE_AND_NULL(rend_data_t, rend_data_free_, (data))
rend_data_t *rend_data_dup(const rend_data_t *data);
rend_data_t *rend_data_client_create(const char *onion_address,
const char *desc_id,
diff --git a/src/or/hs_descriptor.h b/src/or/hs_descriptor.h
index 19158e910..09979410e 100644
--- a/src/or/hs_descriptor.h
+++ b/src/or/hs_descriptor.h
@@ -209,7 +209,8 @@ hs_desc_is_supported_version(uint32_t version)
/* Public API. */
void hs_descriptor_free_(hs_descriptor_t *desc);
-#define hs_descriptor_free(desc) FREE_AND_NULL(hs_descriptor_t, hs_descriptor_free_, (desc))
+#define hs_descriptor_free(desc) \
+ FREE_AND_NULL(hs_descriptor_t, hs_descriptor_free_, (desc))
void hs_desc_plaintext_data_free_(hs_desc_plaintext_data_t *desc);
#define hs_desc_plaintext_data_free(desc) \
FREE_AND_NULL(hs_desc_plaintext_data_t, hs_desc_plaintext_data_free_, (desc))
@@ -243,7 +244,8 @@ size_t hs_desc_plaintext_obj_size(const hs_desc_plaintext_data_t *data);
hs_desc_intro_point_t *hs_desc_intro_point_new(void);
void hs_desc_intro_point_free_(hs_desc_intro_point_t *ip);
-#define hs_desc_intro_point_free(ip) FREE_AND_NULL(hs_desc_intro_point_t, hs_desc_intro_point_free_, (ip))
+#define hs_desc_intro_point_free(ip) \
+ FREE_AND_NULL(hs_desc_intro_point_t, hs_desc_intro_point_free_, (ip))
link_specifier_t *hs_desc_lspec_to_trunnel(
const hs_desc_link_specifier_t *spec);
diff --git a/src/or/hs_ident.h b/src/or/hs_ident.h
index b91e5c79b..91ec389aa 100644
--- a/src/or/hs_ident.h
+++ b/src/or/hs_ident.h
@@ -120,13 +120,15 @@ hs_ident_circuit_t *hs_ident_circuit_new(
const ed25519_public_key_t *identity_pk,
hs_ident_circuit_type_t circuit_type);
void hs_ident_circuit_free_(hs_ident_circuit_t *ident);
-#define hs_ident_circuit_free(id) FREE_AND_NULL(hs_ident_circuit_t, hs_ident_circuit_free_, (id))
+#define hs_ident_circuit_free(id) \
+ FREE_AND_NULL(hs_ident_circuit_t, hs_ident_circuit_free_, (id))
hs_ident_circuit_t *hs_ident_circuit_dup(const hs_ident_circuit_t *src);
/* Directory connection identifier API. */
hs_ident_dir_conn_t *hs_ident_dir_conn_dup(const hs_ident_dir_conn_t *src);
void hs_ident_dir_conn_free_(hs_ident_dir_conn_t *ident);
-#define hs_ident_dir_conn_free(id) FREE_AND_NULL(hs_ident_dir_conn_t, hs_ident_dir_conn_free_, (id))
+#define hs_ident_dir_conn_free(id) \
+ FREE_AND_NULL(hs_ident_dir_conn_t, hs_ident_dir_conn_free_, (id))
void hs_ident_dir_conn_init(const ed25519_public_key_t *identity_pk,
const ed25519_public_key_t *blinded_pk,
hs_ident_dir_conn_t *ident);
@@ -135,7 +137,8 @@ void hs_ident_dir_conn_init(const ed25519_public_key_t *identity_pk,
hs_ident_edge_conn_t *hs_ident_edge_conn_new(
const ed25519_public_key_t *identity_pk);
void hs_ident_edge_conn_free_(hs_ident_edge_conn_t *ident);
-#define hs_ident_edge_conn_free(id) FREE_AND_NULL(hs_ident_edge_conn_t, hs_ident_edge_conn_free_, (id))
+#define hs_ident_edge_conn_free(id) \
+ FREE_AND_NULL(hs_ident_edge_conn_t, hs_ident_edge_conn_free_, (id))
/* Validators */
int hs_ident_intro_circ_is_valid(const hs_ident_circuit_t *ident);
diff --git a/src/or/networkstatus.h b/src/or/networkstatus.h
index 93fde8c2c..791e32adc 100644
--- a/src/or/networkstatus.h
+++ b/src/or/networkstatus.h
@@ -19,7 +19,8 @@ void networkstatus_reset_download_failures(void);
char *networkstatus_read_cached_consensus(const char *flavorname);
int router_reload_consensus_networkstatus(void);
void routerstatus_free_(routerstatus_t *rs);
-#define routerstatus_free(rs) FREE_AND_NULL(routerstatus_t, routerstatus_free_, (rs))
+#define routerstatus_free(rs) \
+ FREE_AND_NULL(routerstatus_t, routerstatus_free_, (rs))
void networkstatus_vote_free_(networkstatus_t *ns);
#define networkstatus_vote_free(ns) \
FREE_AND_NULL(networkstatus_t, networkstatus_vote_free_, (ns))
@@ -128,13 +129,15 @@ int32_t networkstatus_get_bw_weight(networkstatus_t *ns, const char *weight,
const char *networkstatus_get_flavor_name(consensus_flavor_t flav);
int networkstatus_parse_flavor_name(const char *flavname);
void document_signature_free_(document_signature_t *sig);
-#define document_signature_free(sig) FREE_AND_NULL(document_signature_t, document_signature_free_, (sig))
+#define document_signature_free(sig) \
+ FREE_AND_NULL(document_signature_t, document_signature_free_, (sig))
document_signature_t *document_signature_dup(const document_signature_t *sig);
void networkstatus_free_all(void);
int networkstatus_get_weight_scale_param(networkstatus_t *ns);
void vote_routerstatus_free_(vote_routerstatus_t *rs);
-#define vote_routerstatus_free(rs) FREE_AND_NULL(vote_routerstatus_t, vote_routerstatus_free_, (rs))
+#define vote_routerstatus_free(rs) \
+ FREE_AND_NULL(vote_routerstatus_t, vote_routerstatus_free_, (rs))
#ifdef NETWORKSTATUS_PRIVATE
#ifdef TOR_UNIT_TESTS
diff --git a/src/or/onion.h b/src/or/onion.h
index 48985700e..3b738debe 100644
--- a/src/or/onion.h
+++ b/src/or/onion.h
@@ -32,7 +32,8 @@ typedef struct server_onion_keys_t {
server_onion_keys_t *server_onion_keys_new(void);
void server_onion_keys_free_(server_onion_keys_t *keys);
-#define server_onion_keys_free(keys) FREE_AND_NULL(server_onion_keys_t, server_onion_keys_free_, (keys))
+#define server_onion_keys_free(keys) \
+ FREE_AND_NULL(server_onion_keys_t, server_onion_keys_free_, (keys))
void onion_handshake_state_release(onion_handshake_state_t *state);
diff --git a/src/or/policies.h b/src/or/policies.h
index 55bf9012b..35220a812 100644
--- a/src/or/policies.h
+++ b/src/or/policies.h
@@ -119,7 +119,8 @@ void addr_policy_list_free_(smartlist_t *p);
#define addr_policy_list_free(lst) \
FREE_AND_NULL(smartlist_t, addr_policy_list_free_, (lst))
void addr_policy_free_(addr_policy_t *p);
-#define addr_policy_free(p) FREE_AND_NULL(addr_policy_t, addr_policy_free_, (p))
+#define addr_policy_free(p) \
+ FREE_AND_NULL(addr_policy_t, addr_policy_free_, (p))
void policies_free_all(void);
char *policy_summarize(smartlist_t *policy, sa_family_t family);
@@ -127,7 +128,8 @@ char *policy_summarize(smartlist_t *policy, sa_family_t family);
short_policy_t *parse_short_policy(const char *summary);
char *write_short_policy(const short_policy_t *policy);
void short_policy_free_(short_policy_t *policy);
-#define short_policy_free(p) FREE_AND_NULL(short_policy_t, short_policy_free_, (p))
+#define short_policy_free(p) \
+ FREE_AND_NULL(short_policy_t, short_policy_free_, (p))
int short_policy_is_reject_star(const short_policy_t *policy);
addr_policy_result_t compare_tor_addr_to_short_policy(
const tor_addr_t *addr, uint16_t port,
diff --git a/src/or/proto_socks.h b/src/or/proto_socks.h
index 492cd13cd..02e0aca7e 100644
--- a/src/or/proto_socks.h
+++ b/src/or/proto_socks.h
@@ -12,7 +12,8 @@ struct buf_t;
struct socks_request_t *socks_request_new(void);
void socks_request_free_(struct socks_request_t *req);
-#define socks_request_free(req) FREE_AND_NULL(socks_request_t, socks_request_free_, (req))
+#define socks_request_free(req) \
+ FREE_AND_NULL(socks_request_t, socks_request_free_, (req))
int fetch_from_buf_socks(struct buf_t *buf, socks_request_t *req,
int log_sockstype, int safe_socks);
int fetch_from_buf_socks_client(buf_t *buf, int state, char **reason);
diff --git a/src/or/protover.h b/src/or/protover.h
index 3c0530a3a..2539c92c3 100644
--- a/src/or/protover.h
+++ b/src/or/protover.h
@@ -84,7 +84,8 @@ STATIC const char *protocol_type_to_str(protocol_type_t pr);
STATIC int str_to_protocol_type(const char *s, protocol_type_t *pr_out);
STATIC void proto_entry_free_(proto_entry_t *entry);
#endif
-#define proto_entry_free(entry) FREE_AND_NULL(proto_entry_t, proto_entry_free_, (entry))
+#define proto_entry_free(entry) \
+ FREE_AND_NULL(proto_entry_t, proto_entry_free_, (entry))
#endif /* defined(PROTOVER_PRIVATE) */
diff --git a/src/or/relay.h b/src/or/relay.h
index 417942adb..95b8beb3b 100644
--- a/src/or/relay.h
+++ b/src/or/relay.h
@@ -52,7 +52,8 @@ int have_been_under_memory_pressure(void);
/* For channeltls.c */
void packed_cell_free_(packed_cell_t *cell);
-#define packed_cell_free(cell) FREE_AND_NULL(packed_cell_t, packed_cell_free_, (cell))
+#define packed_cell_free(cell) \
+ FREE_AND_NULL(packed_cell_t, packed_cell_free_, (cell))
void cell_queue_init(cell_queue_t *queue);
void cell_queue_clear(cell_queue_t *queue);
@@ -96,7 +97,8 @@ typedef struct address_ttl_s {
int ttl;
} address_ttl_t;
STATIC void address_ttl_free_(address_ttl_t *addr);
-#define address_ttl_free(addr) FREE_AND_NULL(address_ttl_t, address_ttl_free_, (addr))
+#define address_ttl_free(addr) \
+ FREE_AND_NULL(address_ttl_t, address_ttl_free_, (addr))
STATIC int resolved_cell_parse(const cell_t *cell, const relay_header_t *rh,
smartlist_t *addresses_out, int *errcode_out);
STATIC int connection_edge_process_resolved_cell(edge_connection_t *conn,
diff --git a/src/or/rendcache.h b/src/or/rendcache.h
index 30e6a0cc9..66e978564 100644
--- a/src/or/rendcache.h
+++ b/src/or/rendcache.h
@@ -91,7 +91,8 @@ void rend_cache_increment_allocation(size_t n);
STATIC size_t rend_cache_entry_allocation(const rend_cache_entry_t *e);
STATIC void rend_cache_entry_free_(rend_cache_entry_t *e);
-#define rend_cache_entry_free(e) FREE_AND_NULL(rend_cache_entry_t, rend_cache_entry_free_, (e))
+#define rend_cache_entry_free(e) \
+ FREE_AND_NULL(rend_cache_entry_t, rend_cache_entry_free_, (e))
STATIC void rend_cache_failure_intro_entry_free_(rend_cache_failure_intro_t
*entry);
#define rend_cache_failure_intro_entry_free(e) \
diff --git a/src/or/rendcommon.h b/src/or/rendcommon.h
index 3e1edfbcf..1ed0f6260 100644
--- a/src/or/rendcommon.h
+++ b/src/or/rendcommon.h
@@ -26,14 +26,17 @@ void rend_process_relay_cell(circuit_t *circ, const crypt_path_t *layer_hint,
void rend_service_descriptor_free_(rend_service_descriptor_t *desc);
#define rend_service_descriptor_free(desc) \
- FREE_AND_NULL(rend_service_descriptor_t, rend_service_descriptor_free_, (desc))
+ FREE_AND_NULL(rend_service_descriptor_t, rend_service_descriptor_free_, \
+ (desc))
int rend_get_service_id(crypto_pk_t *pk, char *out);
void rend_encoded_v2_service_descriptor_free_(
rend_encoded_v2_service_descriptor_t *desc);
#define rend_encoded_v2_service_descriptor_free(desc) \
- FREE_AND_NULL(rend_encoded_v2_service_descriptor_t, rend_encoded_v2_service_descriptor_free_, (desc))
+ FREE_AND_NULL(rend_encoded_v2_service_descriptor_t, \
+ rend_encoded_v2_service_descriptor_free_, (desc))
void rend_intro_point_free_(rend_intro_point_t *intro);
-#define rend_intro_point_free(intro) FREE_AND_NULL(rend_intro_point_t, rend_intro_point_free_, (intro))
+#define rend_intro_point_free(intro) \
+ FREE_AND_NULL(rend_intro_point_t, rend_intro_point_free_, (intro))
int rend_valid_v2_service_id(const char *query);
int rend_valid_descriptor_id(const char *query);
diff --git a/src/or/rendservice.h b/src/or/rendservice.h
index 8d11c7682..70ebd8786 100644
--- a/src/or/rendservice.h
+++ b/src/or/rendservice.h
@@ -118,7 +118,8 @@ typedef struct rend_service_t {
} rend_service_t;
STATIC void rend_service_free_(rend_service_t *service);
-#define rend_service_free(s) FREE_AND_NULL(rend_service_t, rend_service_free_, (s))
+#define rend_service_free(s) \
+ FREE_AND_NULL(rend_service_t, rend_service_free_, (s))
STATIC char *rend_service_sos_poison_path(const rend_service_t *service);
STATIC int rend_service_verify_single_onion_poison(
const rend_service_t *s,
@@ -190,11 +191,13 @@ rend_service_port_config_t *rend_service_parse_port_config(const char *string,
char **err_msg_out);
void rend_service_port_config_free_(rend_service_port_config_t *p);
#define rend_service_port_config_free(p) \
- FREE_AND_NULL(rend_service_port_config_t, rend_service_port_config_free_, (p))
+ FREE_AND_NULL(rend_service_port_config_t, rend_service_port_config_free_, \
+ (p))
void rend_authorized_client_free_(rend_authorized_client_t *client);
#define rend_authorized_client_free(client) \
- FREE_AND_NULL(rend_authorized_client_t, rend_authorized_client_free_, (client))
+ FREE_AND_NULL(rend_authorized_client_t, rend_authorized_client_free_, \
+ (client))
/** Return value from rend_service_add_ephemeral. */
typedef enum {
diff --git a/src/or/replaycache.h b/src/or/replaycache.h
index 6b845b929..81a8d907f 100644
--- a/src/or/replaycache.h
+++ b/src/or/replaycache.h
@@ -34,7 +34,8 @@ struct replaycache_s {
/* replaycache_t free/new */
void replaycache_free_(replaycache_t *r);
-#define replaycache_free(r) FREE_AND_NULL(replaycache_t, replaycache_free_, (r))
+#define replaycache_free(r) \
+ FREE_AND_NULL(replaycache_t, replaycache_free_, (r))
replaycache_t * replaycache_new(time_t horizon, time_t interval);
#ifdef REPLAYCACHE_PRIVATE
diff --git a/src/or/routerlist.h b/src/or/routerlist.h
index ab510dee3..83f4d1002 100644
--- a/src/or/routerlist.h
+++ b/src/or/routerlist.h
@@ -97,7 +97,8 @@ const char *signed_descriptor_get_body(const signed_descriptor_t *desc);
const char *signed_descriptor_get_annotations(const signed_descriptor_t *desc);
routerlist_t *router_get_routerlist(void);
void routerinfo_free_(routerinfo_t *router);
-#define routerinfo_free(router) FREE_AND_NULL(routerinfo_t, routerinfo_free_, (router))
+#define routerinfo_free(router) \
+ FREE_AND_NULL(routerinfo_t, routerinfo_free_, (router))
void extrainfo_free_(extrainfo_t *extrainfo);
#define extrainfo_free(ei) FREE_AND_NULL(extrainfo_t, extrainfo_free_, (ei))
void routerlist_free_(routerlist_t *rl);
@@ -195,7 +196,8 @@ dir_server_t *fallback_dir_server_new(const tor_addr_t *addr,
void dir_server_add(dir_server_t *ent);
void authority_cert_free_(authority_cert_t *cert);
-#define authority_cert_free(cert) FREE_AND_NULL(authority_cert_t, authority_cert_free_, (cert))
+#define authority_cert_free(cert) \
+ FREE_AND_NULL(authority_cert_t, authority_cert_free_, (cert))
void clear_dir_servers(void);
void update_consensus_router_descriptor_downloads(time_t now, int is_vote,
networkstatus_t *consensus);
1
0
commit 5ee0cccd49e57fad8c810e817d912d4a61dbc96c
Merge: 44010c6fc 7ca5f4bf0
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Dec 8 14:58:43 2017 -0500
Merge branch 'macro_free_v2_squashed'
changes/bug24337 | 8 ++++
configure.ac | 1 -
doc/HACKING/CodingStandards.md | 40 ++++++++++++++++++
src/common/address.c | 6 +--
src/common/address.h | 13 +++---
src/common/aes.c | 4 +-
src/common/aes.h | 4 +-
src/common/buffers.c | 2 +-
src/common/buffers.h | 3 +-
src/common/compat.c | 5 ++-
src/common/compat_libevent.c | 4 +-
src/common/compat_libevent.h | 8 +++-
src/common/compat_threads.c | 4 +-
src/common/compat_threads.h | 6 ++-
src/common/compress.c | 2 +-
src/common/compress.h | 4 +-
src/common/compress_lzma.c | 2 +-
src/common/compress_lzma.h | 5 ++-
src/common/compress_zlib.c | 2 +-
src/common/compress_zlib.h | 5 ++-
src/common/compress_zstd.c | 2 +-
src/common/compress_zstd.h | 5 ++-
src/common/confline.c | 2 +-
src/common/confline.h | 7 ++-
src/common/container.c | 19 ++++++---
src/common/container.h | 27 +++++++++---
src/common/crypto.c | 10 ++---
src/common/crypto.h | 19 ++++++---
src/common/crypto_ed25519.c | 2 +-
src/common/crypto_ed25519.h | 5 ++-
src/common/di_ops.c | 2 +-
src/common/di_ops.h | 7 ++-
src/common/handles.h | 4 +-
src/common/log.c | 11 +++--
src/common/memarea.c | 2 +-
src/common/memarea.h | 7 ++-
src/common/procmon.c | 2 +-
src/common/procmon.h | 4 +-
src/common/sandbox.c | 6 ++-
src/common/storagedir.c | 2 +-
src/common/storagedir.h | 5 ++-
src/common/timers.c | 2 +-
src/common/timers.h | 3 +-
src/common/tortls.c | 4 +-
src/common/tortls.h | 7 ++-
src/common/util.c | 2 +-
src/common/util.h | 25 ++++++++++-
src/common/workqueue.c | 5 ++-
src/or/addressmap.c | 35 ++++++++++-----
src/or/bridges.c | 7 ++-
src/or/channel.c | 26 ++++++------
src/or/channel.h | 9 +++-
src/or/circuitbuild.c | 2 +-
src/or/circuitbuild.h | 4 +-
src/or/circuitlist.c | 4 +-
src/or/circuitlist.h | 3 +-
src/or/circuitmux.c | 2 +-
src/or/circuitmux.h | 4 +-
src/or/config.c | 10 +++--
src/or/config.h | 12 ++++--
src/or/confparse.c | 2 +-
src/or/confparse.h | 7 ++-
src/or/connection.c | 15 ++++---
src/or/connection.h | 6 ++-
src/or/connection_edge.c | 12 +++---
src/or/connection_or.c | 8 ++--
src/or/connection_or.h | 7 ++-
src/or/conscache.c | 2 +-
src/or/conscache.h | 7 ++-
src/or/consdiffmgr.c | 17 ++++++--
src/or/control.c | 5 ++-
src/or/cpuworker.c | 19 +++++++--
src/or/dircollate.c | 7 ++-
src/or/dircollate.h | 4 +-
src/or/directory.c | 2 +-
src/or/directory.h | 4 +-
src/or/dirserv.c | 2 +-
src/or/dirserv.h | 4 +-
src/or/dirvote.c | 7 ++-
src/or/dirvote.h | 4 +-
src/or/dns.c | 10 ++---
src/or/dnsserv.c | 4 +-
src/or/entrynodes.c | 8 ++--
src/or/entrynodes.h | 21 +++++++--
src/or/ext_orport.c | 2 +-
src/or/ext_orport.h | 6 ++-
src/or/fp_pair.c | 2 +-
src/or/fp_pair.h | 7 ++-
src/or/geoip.c | 5 ++-
src/or/hs_cache.c | 44 ++++++++++++-------
src/or/hs_circuitmap.c | 5 ++-
src/or/hs_common.c | 2 +-
src/or/hs_common.h | 4 +-
src/or/hs_descriptor.c | 10 ++---
src/or/hs_descriptor.h | 21 ++++++---
src/or/hs_ident.c | 6 +--
src/or/hs_ident.h | 12 ++++--
src/or/hs_service.c | 12 +++---
src/or/hs_service.h | 23 ++++++----
src/or/microdesc.h | 6 ++-
src/or/networkstatus.c | 8 ++--
src/or/networkstatus.h | 16 +++++--
src/or/nodelist.c | 6 ++-
src/or/onion.c | 2 +-
src/or/onion.h | 4 +-
src/or/onion_fast.c | 2 +-
src/or/onion_fast.h | 4 +-
src/or/onion_ntor.c | 2 +-
src/or/onion_ntor.h | 4 +-
src/or/policies.c | 10 ++---
src/or/policies.h | 12 ++++--
src/or/proto_socks.c | 2 +-
src/or/proto_socks.h | 4 +-
src/or/protover.c | 2 +-
src/or/protover.h | 4 +-
src/or/relay.c | 4 +-
src/or/relay.h | 8 +++-
src/or/rendcache.c | 32 +++++++-------
src/or/rendcache.h | 18 +++++---
src/or/rendclient.c | 14 +++---
src/or/rendcommon.c | 6 +--
src/or/rendcommon.h | 14 ++++--
src/or/rendservice.c | 18 ++++----
src/or/rendservice.h | 22 +++++++---
src/or/rephist.c | 20 ++++++---
src/or/replaycache.c | 2 +-
src/or/replaycache.h | 4 +-
src/or/router.c | 3 +-
src/or/router.h | 4 +-
src/or/routerlist.c | 40 ++++++++++++------
src/or/routerlist.h | 14 ++++--
src/or/routerset.c | 2 +-
src/or/routerset.h | 3 +-
src/or/scheduler_kist.c | 4 +-
src/or/shared_random.c | 4 +-
src/or/shared_random.h | 3 +-
src/or/shared_random_state.c | 14 ++++--
src/or/shared_random_state.h | 2 +-
src/or/statefile.c | 2 +-
src/or/statefile.h | 3 +-
src/or/torcert.c | 4 +-
src/or/torcert.h | 7 ++-
src/or/transports.c | 2 +-
src/or/transports.h | 3 +-
src/test/test-timers.c | 2 +-
src/test/test.c | 6 +--
src/test/test_address.c | 16 +++----
src/test/test_cell_queue.c | 4 +-
src/test/test_channel.c | 2 +-
src/test/test_circuitlist.c | 28 ++++++------
src/test/test_dir.c | 6 +--
src/test/test_dir_handle_get.c | 96 +++++++++++++++++++++---------------------
src/test/test_dns.c | 6 +--
src/test/test_entryconn.c | 34 +++++++--------
src/test/test_entrynodes.c | 4 +-
src/test/test_extorport.c | 10 ++---
src/test/test_handles.c | 2 +
src/test/test_hs_cache.c | 2 +-
src/test/test_hs_client.c | 12 +++---
src/test/test_hs_intropoint.c | 38 ++++++++---------
src/test/test_hs_service.c | 16 +++----
src/test/test_link_handshake.c | 14 +++---
src/test/test_oom.c | 2 +-
src/test/test_policy.c | 8 ++--
src/test/test_rendcache.c | 8 ++--
src/test/test_replay.c | 2 +-
src/test/test_routerlist.c | 2 +-
src/test/test_routerset.c | 56 ++++++++++++------------
src/test/test_shared_random.c | 2 +-
169 files changed, 976 insertions(+), 555 deletions(-)
diff --cc src/or/channel.c
index 5b9d860ba,90536b146..7fa976817
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@@ -159,15 -202,39 +160,15 @@@ HT_PROTOTYPE(channel_idmap, channel_idm
HT_GENERATE2(channel_idmap, channel_idmap_entry_s, node, channel_idmap_hash,
channel_idmap_eq, 0.5, tor_reallocarray_, tor_free_)
-static cell_queue_entry_t * cell_queue_entry_dup(cell_queue_entry_t *q);
-#if 0
-static int cell_queue_entry_is_padding(cell_queue_entry_t *q);
-#endif
-static cell_queue_entry_t *
-cell_queue_entry_new_fixed(cell_t *cell);
-static cell_queue_entry_t *
-cell_queue_entry_new_var(var_cell_t *var_cell);
-static int is_destroy_cell(channel_t *chan,
- const cell_queue_entry_t *q, circid_t *circid_out);
-
-static void channel_assert_counter_consistency(void);
-
/* Functions to maintain the digest map */
-static void channel_add_to_digest_map(channel_t *chan);
static void channel_remove_from_digest_map(channel_t *chan);
- 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);
-/*
- * Flush cells from just the outgoing queue without trying to get them
- * from circuits; used internall by channel_flush_some_cells().
- */
-static ssize_t
-channel_flush_some_cells_from_outgoing_queue(channel_t *chan,
- ssize_t num_cells);
+ static void channel_force_xfree(channel_t *chan);
-static void channel_free_list(smartlist_t *channels, int mark_for_close);
++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);
++ 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
-channel_write_cell_queue_entry(channel_t *chan, cell_queue_entry_t *q);
/***********************************
* Channel state utility functions *
@@@ -962,8 -1067,9 +963,8 @@@ channel_listener_free_(channel_listener
*/
static void
- channel_force_free(channel_t *chan)
+ channel_force_xfree(channel_t *chan)
{
- cell_queue_entry_t *cell, *cell_tmp;
tor_assert(chan);
log_debug(LD_CHANNEL,
@@@ -1429,18 -1668,250 +1430,17 @@@ channel_clear_remote_end(channel_t *cha
}
/**
- * Set the remote end metadata (identity_digest/nickname) of a channel
+ * Write to a channel the given packed cell.
*
- * Return 0 on success or -1 on error.
- * This function sets new remote end info on a channel; this is intended
- * for use by the lower layer.
- */
-
-void
-channel_set_remote_end(channel_t *chan,
- const char *identity_digest,
- const char *nickname)
-{
- int was_in_digest_map, should_be_in_digest_map, state_not_in_map;
-
- tor_assert(chan);
-
- log_debug(LD_CHANNEL,
- "Setting remote endpoint identity on channel %p with "
- "global ID " U64_FORMAT " to nickname %s, digest %s",
- chan, U64_PRINTF_ARG(chan->global_identifier),
- nickname ? nickname : "(null)",
- identity_digest ?
- hex_str(identity_digest, DIGEST_LEN) : "(null)");
-
- state_not_in_map = CHANNEL_CONDEMNED(chan);
-
- was_in_digest_map =
- !state_not_in_map &&
- chan->registered &&
- !tor_digest_is_zero(chan->identity_digest);
- should_be_in_digest_map =
- !state_not_in_map &&
- chan->registered &&
- (identity_digest &&
- !tor_digest_is_zero(identity_digest));
-
- if (was_in_digest_map)
- /* We should always remove it; we'll add it back if we're writing
- * in a new digest.
- */
- channel_remove_from_digest_map(chan);
-
- if (identity_digest) {
- memcpy(chan->identity_digest,
- identity_digest,
- sizeof(chan->identity_digest));
-
- } else {
- memset(chan->identity_digest, 0,
- sizeof(chan->identity_digest));
- }
-
- tor_free(chan->nickname);
- if (nickname)
- chan->nickname = tor_strdup(nickname);
-
- /* Put it in the digest map if we should */
- if (should_be_in_digest_map)
- channel_add_to_digest_map(chan);
-}
-
-/**
- * Duplicate a cell queue entry; this is a shallow copy intended for use
- * in channel_write_cell_queue_entry().
- */
-
-static cell_queue_entry_t *
-cell_queue_entry_dup(cell_queue_entry_t *q)
-{
- cell_queue_entry_t *rv = NULL;
-
- tor_assert(q);
-
- rv = tor_malloc(sizeof(*rv));
- memcpy(rv, q, sizeof(*rv));
-
- return rv;
-}
-
-/**
- * Free a cell_queue_entry_t; the handed_off parameter indicates whether
- * the contents were passed to the lower layer (it is responsible for
- * them) or not (we should free).
- */
-
-STATIC void
-cell_queue_entry_xfree(cell_queue_entry_t *q, int handed_off)
-{
- if (!q) return;
-
- if (!handed_off) {
- /*
- * If we handed it off, the recipient becomes responsible (or
- * with packed cells the channel_t subclass calls packed_cell
- * free after writing out its contents; see, e.g.,
- * channel_tls_write_packed_cell_method(). Otherwise, we have
- * to take care of it here if possible.
- */
- switch (q->type) {
- case CELL_QUEUE_FIXED:
- if (q->u.fixed.cell) {
- /*
- * There doesn't seem to be a cell_free() function anywhere in the
- * pre-channel code; just use tor_free()
- */
- tor_free(q->u.fixed.cell);
- }
- break;
- case CELL_QUEUE_PACKED:
- if (q->u.packed.packed_cell) {
- packed_cell_free(q->u.packed.packed_cell);
- }
- break;
- case CELL_QUEUE_VAR:
- if (q->u.var.var_cell) {
- /*
- * This one's in connection_or.c; it'd be nice to figure out the
- * whole flow of cells from one end to the other and factor the
- * cell memory management functions like this out of the specific
- * TLS lower layer.
- */
- var_cell_free(q->u.var.var_cell);
- }
- break;
- default:
- /*
- * Nothing we can do if we don't know the type; this will
- * have been warned about elsewhere.
- */
- break;
- }
- }
- tor_free(q);
-}
-
-#if 0
-/**
- * Check whether a cell queue entry is padding; this is a helper function
- * for channel_write_cell_queue_entry()
- */
-
-static int
-cell_queue_entry_is_padding(cell_queue_entry_t *q)
-{
- tor_assert(q);
-
- if (q->type == CELL_QUEUE_FIXED) {
- if (q->u.fixed.cell) {
- if (q->u.fixed.cell->command == CELL_PADDING ||
- q->u.fixed.cell->command == CELL_VPADDING) {
- return 1;
- }
- }
- } else if (q->type == CELL_QUEUE_VAR) {
- if (q->u.var.var_cell) {
- if (q->u.var.var_cell->command == CELL_PADDING ||
- q->u.var.var_cell->command == CELL_VPADDING) {
- return 1;
- }
- }
- }
-
- return 0;
-}
-#endif /* 0 */
-
-/**
- * Allocate a new cell queue entry for a fixed-size cell
- */
-
-static cell_queue_entry_t *
-cell_queue_entry_new_fixed(cell_t *cell)
-{
- cell_queue_entry_t *q = NULL;
-
- tor_assert(cell);
-
- q = tor_malloc(sizeof(*q));
- q->type = CELL_QUEUE_FIXED;
- q->u.fixed.cell = cell;
-
- return q;
-}
-
-/**
- * Allocate a new cell queue entry for a variable-size cell
- */
-
-static cell_queue_entry_t *
-cell_queue_entry_new_var(var_cell_t *var_cell)
-{
- cell_queue_entry_t *q = NULL;
-
- tor_assert(var_cell);
-
- q = tor_malloc(sizeof(*q));
- q->type = CELL_QUEUE_VAR;
- q->u.var.var_cell = var_cell;
-
- return q;
-}
-
-/**
- * Ask how big the cell contained in a cell_queue_entry_t is
- */
-
-static size_t
-channel_get_cell_queue_entry_size(channel_t *chan, cell_queue_entry_t *q)
-{
- size_t rv = 0;
-
- tor_assert(chan);
- tor_assert(q);
-
- switch (q->type) {
- case CELL_QUEUE_FIXED:
- rv = get_cell_network_size(chan->wide_circ_ids);
- break;
- case CELL_QUEUE_VAR:
- rv = get_var_cell_header_size(chan->wide_circ_ids) +
- (q->u.var.var_cell ? q->u.var.var_cell->payload_len : 0);
- break;
- case CELL_QUEUE_PACKED:
- rv = get_cell_network_size(chan->wide_circ_ids);
- break;
- default:
- tor_assert_nonfatal_unreached_once();
- }
-
- return rv;
-}
-
-/**
- * Write to a channel based on a cell_queue_entry_t
*
- * Given a cell_queue_entry_t filled out by the caller, try to send the cell
- * and queue it if we can't.
+ * Two possible errors can happen. Either the channel is not opened or the
+ * lower layer (specialized channel) failed to write it. In both cases, it is
+ * the caller responsability to free the cell.
*/
-
-static void
-channel_write_cell_queue_entry(channel_t *chan, cell_queue_entry_t *q)
+static int
+write_packed_cell(channel_t *chan, packed_cell_t *cell)
{
- int result = 0, sent = 0;
- cell_queue_entry_t *tmp = NULL;
+ int ret = -1;
size_t cell_bytes;
tor_assert(chan);
diff --cc src/or/channel.h
index d88a77c9a,909813cee..0f685011a
--- a/src/or/channel.h
+++ b/src/or/channel.h
@@@ -457,9 -511,16 +457,12 @@@ void channel_close_from_lower_layer(cha
void channel_close_for_error(channel_t *chan);
void channel_closed(channel_t *chan);
-void channel_listener_close_from_lower_layer(channel_listener_t *chan_l);
-void channel_listener_close_for_error(channel_listener_t *chan_l);
-void channel_listener_closed(channel_listener_t *chan_l);
-
/* Free a channel */
- void channel_free(channel_t *chan);
- void channel_listener_free(channel_listener_t *chan_l);
+ void channel_free_(channel_t *chan);
+ #define channel_free(chan) FREE_AND_NULL(channel_t, channel_free_, (chan))
+ void channel_listener_free_(channel_listener_t *chan_l);
+ #define channel_listener_free(chan_l) \
+ FREE_AND_NULL(channel_listener_t, channel_listener_free_, (chan_l))
/* State/metadata setters */
diff --cc src/or/protover.h
index 83a728e62,2539c92c3..8bbc2fc71
--- a/src/or/protover.h
+++ b/src/or/protover.h
@@@ -82,10 -82,11 +82,12 @@@ STATIC smartlist_t *parse_protocol_list
STATIC char *encode_protocol_list(const smartlist_t *sl);
STATIC const char *protocol_type_to_str(protocol_type_t pr);
STATIC int str_to_protocol_type(const char *s, protocol_type_t *pr_out);
- STATIC void proto_entry_free(proto_entry_t *entry);
+ STATIC void proto_entry_free_(proto_entry_t *entry);
-#endif
+ #define proto_entry_free(entry) \
+ FREE_AND_NULL(proto_entry_t, proto_entry_free_, (entry))
+#endif /* !defined(HAVE_RUST) && defined(TOR_UNIT_TESTS) */
+
#endif /* defined(PROTOVER_PRIVATE) */
#endif /* !defined(TOR_PROTOVER_H) */
diff --cc src/or/rendservice.h
index 15badce6a,70ebd8786..88da7b866
--- a/src/or/rendservice.h
+++ b/src/or/rendservice.h
@@@ -183,11 -189,26 +189,17 @@@ void rend_service_init(void)
rend_service_port_config_t *rend_service_parse_port_config(const char *string,
const char *sep,
char **err_msg_out);
- void rend_service_port_config_free(rend_service_port_config_t *p);
-
- void rend_authorized_client_free(rend_authorized_client_t *client);
+ void rend_service_port_config_free_(rend_service_port_config_t *p);
+ #define rend_service_port_config_free(p) \
+ FREE_AND_NULL(rend_service_port_config_t, rend_service_port_config_free_, \
+ (p))
+
+ void rend_authorized_client_free_(rend_authorized_client_t *client);
+ #define rend_authorized_client_free(client) \
+ FREE_AND_NULL(rend_authorized_client_t, rend_authorized_client_free_, \
+ (client))
-/** Return value from rend_service_add_ephemeral. */
-typedef enum {
- RSAE_BADAUTH = -5, /**< Invalid auth_type/auth_clients */
- RSAE_BADVIRTPORT = -4, /**< Invalid VIRTPORT/TARGET(s) */
- RSAE_ADDREXISTS = -3, /**< Onion address collision */
- RSAE_BADPRIVKEY = -2, /**< Invalid public key */
- RSAE_INTERNAL = -1, /**< Internal error */
- RSAE_OKAY = 0 /**< Service added as expected */
-} rend_service_add_ephemeral_status_t;
-rend_service_add_ephemeral_status_t rend_service_add_ephemeral(crypto_pk_t *pk,
+hs_service_add_ephemeral_status_t rend_service_add_ephemeral(crypto_pk_t *pk,
smartlist_t *ports,
int max_streams_per_circuit,
int max_streams_close_circuit,
diff --cc src/test/test_channel.c
index 38b69a9ad,594372693..55d43a04e
--- a/src/test/test_channel.c
+++ b/src/test/test_channel.c
@@@ -523,162 -640,152 +523,162 @@@ test_channel_dumpstats(void *arg
return;
}
+/* Test outbound cell. The callstack is:
+ * channel_flush_some_cells()
+ * -> channel_flush_from_first_active_circuit()
+ * -> channel_write_packed_cell()
+ * -> write_packed_cell()
+ * -> chan->write_packed_cell() fct ptr.
+ *
+ * This test goes from a cell in a circuit up to the channel write handler
+ * that should put them on the connection outbuf. */
static void
-test_channel_flush(void *arg)
+test_channel_outbound_cell(void *arg)
{
- channel_t *ch = NULL;
- cell_t *cell = NULL;
- packed_cell_t *p_cell = NULL;
- var_cell_t *v_cell = NULL;
- int init_count;
-
- (void)arg;
+ int old_count;
+ channel_t *chan = NULL;
+ packed_cell_t *p_cell = NULL, *p_cell2 = NULL;
+ origin_circuit_t *circ = NULL;
+ cell_queue_t *queue;
- ch = new_fake_channel();
- tt_assert(ch);
+ (void) arg;
- /* Cache the original count */
- init_count = test_cells_written;
+ /* The channel will be freed so we need to hijack this so the scheduler
+ * doesn't get confused. */
+ MOCK(scheduler_release_channel, scheduler_release_channel_mock);
- /* Stop accepting so we can queue some */
- test_chan_accept_cells = 0;
+ /* Accept cells to lower layer */
+ test_chan_accept_cells = 1;
- /* Queue a regular cell */
- cell = tor_malloc_zero(sizeof(cell_t));
- make_fake_cell(cell);
- channel_write_cell(ch, cell);
- /* It should be queued, so assert that we didn't write it */
- tt_int_op(test_cells_written, OP_EQ, init_count);
-
- /* Queue a var cell */
- v_cell = tor_malloc_zero(sizeof(var_cell_t) + CELL_PAYLOAD_SIZE);
- make_fake_var_cell(v_cell);
- channel_write_var_cell(ch, v_cell);
- /* It should be queued, so assert that we didn't write it */
- tt_int_op(test_cells_written, OP_EQ, init_count);
-
- /* Try a packed cell now */
+ /* Setup a valid circuit to queue a cell. */
+ circ = origin_circuit_new();
+ tt_assert(circ);
+ /* Circuit needs an origin purpose to be considered origin. */
+ TO_CIRCUIT(circ)->purpose = CIRCUIT_PURPOSE_C_GENERAL;
+ TO_CIRCUIT(circ)->n_circ_id = 42;
+ /* This is the outbound test so use the next channel queue. */
+ queue = &TO_CIRCUIT(circ)->n_chan_cells;
+ /* Setup packed cell to queue on the circuit. */
p_cell = packed_cell_new();
tt_assert(p_cell);
- channel_write_packed_cell(ch, p_cell);
- /* It should be queued, so assert that we didn't write it */
- tt_int_op(test_cells_written, OP_EQ, init_count);
-
- /* Now allow writes through again */
- test_chan_accept_cells = 1;
-
- /* ...and flush */
- channel_flush_cells(ch);
-
- /* All three should have gone through */
- tt_int_op(test_cells_written, OP_EQ, init_count + 3);
-
- done:
- tor_free(ch);
-
- return;
-}
-
-/**
- * Channel flush tests that require cmux mocking
- */
-
-static void
-test_channel_flushmux(void *arg)
-{
- channel_t *ch = NULL;
- int old_count, q_len_before, q_len_after;
- ssize_t result;
-
- (void)arg;
-
- /* Install mocks we need for this test */
- MOCK(channel_flush_from_first_active_circuit,
- chan_test_channel_flush_from_first_active_circuit_mock);
- MOCK(circuitmux_num_cells,
- chan_test_circuitmux_num_cells_mock);
-
- ch = new_fake_channel();
- tt_assert(ch);
- ch->cmux = circuitmux_alloc();
-
+ p_cell2 = packed_cell_new();
+ tt_assert(p_cell2);
+ /* Setup a channel to put the circuit on. */
+ chan = new_fake_channel();
+ tt_assert(chan);
+ chan->state = CHANNEL_STATE_OPENING;
+ channel_change_state_open(chan);
+ /* Outbound channel. */
+ channel_mark_outgoing(chan);
+ /* Try to register it so we can clean it through the channel cleanup
+ * process. */
+ channel_register(chan);
+ tt_int_op(chan->registered, OP_EQ, 1);
+ /* Set EWMA policy so we can pick it when flushing. */
+ channel_set_cmux_policy_everywhere(&ewma_policy);
+ tt_ptr_op(circuitmux_get_policy(chan->cmux), OP_EQ, &ewma_policy);
+
+ /* Register circuit to the channel circid map which will attach the circuit
+ * to the channel's cmux as well. */
+ circuit_set_n_circid_chan(TO_CIRCUIT(circ), 42, chan);
+ tt_int_op(channel_num_circuits(chan), OP_EQ, 1);
+ tt_assert(!TO_CIRCUIT(circ)->next_active_on_n_chan);
+ tt_assert(!TO_CIRCUIT(circ)->prev_active_on_n_chan);
+ /* Test the cmux state. */
+ tt_ptr_op(TO_CIRCUIT(circ)->n_mux, OP_EQ, chan->cmux);
+ tt_int_op(circuitmux_is_circuit_attached(chan->cmux, TO_CIRCUIT(circ)),
+ OP_EQ, 1);
+
+ /* Flush the channel without any cell on it. */
old_count = test_cells_written;
-
- test_target_cmux = ch->cmux;
- test_cmux_cells = 1;
-
- /* Enable cell acceptance */
- test_chan_accept_cells = 1;
-
- result = channel_flush_some_cells(ch, 1);
-
- tt_int_op(result, OP_EQ, 1);
+ ssize_t flushed = channel_flush_some_cells(chan, 1);
+ tt_i64_op(flushed, OP_EQ, 0);
+ tt_int_op(test_cells_written, OP_EQ, old_count);
+ tt_int_op(channel_more_to_flush(chan), OP_EQ, 0);
+ tt_int_op(circuitmux_num_active_circuits(chan->cmux), OP_EQ, 0);
+ tt_int_op(circuitmux_num_cells(chan->cmux), OP_EQ, 0);
+ tt_int_op(circuitmux_is_circuit_active(chan->cmux, TO_CIRCUIT(circ)),
+ OP_EQ, 0);
+ tt_u64_op(chan->n_cells_xmitted, OP_EQ, 0);
+ tt_u64_op(chan->n_bytes_xmitted, OP_EQ, 0);
+
+ /* Queue cell onto the next queue that is the outbound direction. Than
+ * update its cmux so the circuit can be picked when flushing cells. */
+ cell_queue_append(queue, p_cell);
+ p_cell = NULL;
+ tt_int_op(queue->n, OP_EQ, 1);
+ cell_queue_append(queue, p_cell2);
+ p_cell2 = NULL;
+ tt_int_op(queue->n, OP_EQ, 2);
+
+ update_circuit_on_cmux(TO_CIRCUIT(circ), CELL_DIRECTION_OUT);
+ tt_int_op(circuitmux_num_active_circuits(chan->cmux), OP_EQ, 1);
+ tt_int_op(circuitmux_num_cells(chan->cmux), OP_EQ, 2);
+ tt_int_op(circuitmux_is_circuit_active(chan->cmux, TO_CIRCUIT(circ)),
+ OP_EQ, 1);
+
+ /* From this point on, we have a queued cell on an active circuit attached
+ * to the channel's cmux. */
+
+ /* Flush the first cell. This is going to go down the call stack. */
+ old_count = test_cells_written;
+ flushed = channel_flush_some_cells(chan, 1);
+ tt_i64_op(flushed, OP_EQ, 1);
tt_int_op(test_cells_written, OP_EQ, old_count + 1);
- tt_int_op(test_cmux_cells, OP_EQ, 0);
-
- /* Now try it without accepting to force them into the queue */
- test_chan_accept_cells = 0;
- test_cmux_cells = 1;
- q_len_before = chan_cell_queue_len(&(ch->outgoing_queue));
-
- result = channel_flush_some_cells(ch, 1);
-
- /* We should not have actually flushed any */
- tt_int_op(result, OP_EQ, 0);
+ tt_int_op(circuitmux_num_cells(chan->cmux), OP_EQ, 1);
+ tt_int_op(channel_more_to_flush(chan), OP_EQ, 1);
+ /* Circuit should remain active because there is a second cell queued. */
+ tt_int_op(circuitmux_is_circuit_active(chan->cmux, TO_CIRCUIT(circ)),
+ OP_EQ, 1);
+ /* Should still be attached. */
+ tt_int_op(circuitmux_is_circuit_attached(chan->cmux, TO_CIRCUIT(circ)),
+ OP_EQ, 1);
+ tt_u64_op(chan->n_cells_xmitted, OP_EQ, 1);
+ tt_u64_op(chan->n_bytes_xmitted, OP_EQ, get_cell_network_size(0));
+
+ /* Flush second cell. This is going to go down the call stack. */
+ old_count = test_cells_written;
+ flushed = channel_flush_some_cells(chan, 1);
+ tt_i64_op(flushed, OP_EQ, 1);
tt_int_op(test_cells_written, OP_EQ, old_count + 1);
- /* But we should have gotten to the fake cellgen loop */
- tt_int_op(test_cmux_cells, OP_EQ, 0);
- /* ...and we should have a queued cell */
- q_len_after = chan_cell_queue_len(&(ch->outgoing_queue));
- tt_int_op(q_len_after, OP_EQ, q_len_before + 1);
-
- /* Now accept cells again and drain the queue */
- test_chan_accept_cells = 1;
- channel_flush_cells(ch);
- tt_int_op(test_cells_written, OP_EQ, old_count + 2);
- tt_int_op(chan_cell_queue_len(&(ch->outgoing_queue)), OP_EQ, 0);
-
- test_target_cmux = NULL;
- test_cmux_cells = 0;
+ tt_int_op(circuitmux_num_cells(chan->cmux), OP_EQ, 0);
+ tt_int_op(channel_more_to_flush(chan), OP_EQ, 0);
+ /* No more cells should make the circuit inactive. */
+ tt_int_op(circuitmux_is_circuit_active(chan->cmux, TO_CIRCUIT(circ)),
+ OP_EQ, 0);
+ /* Should still be attached. */
+ tt_int_op(circuitmux_is_circuit_attached(chan->cmux, TO_CIRCUIT(circ)),
+ OP_EQ, 1);
+ tt_u64_op(chan->n_cells_xmitted, OP_EQ, 2);
+ tt_u64_op(chan->n_bytes_xmitted, OP_EQ, get_cell_network_size(0) * 2);
done:
- if (ch)
- circuitmux_free(ch->cmux);
- tor_free(ch);
-
- UNMOCK(channel_flush_from_first_active_circuit);
- UNMOCK(circuitmux_num_cells);
-
- test_chan_accept_cells = 0;
-
- return;
+ if (circ) {
- circuit_free(TO_CIRCUIT(circ));
++ circuit_free_(TO_CIRCUIT(circ));
+ }
+ tor_free(p_cell);
+ channel_free_all();
+ UNMOCK(scheduler_release_channel);
}
+/* Test inbound cell. The callstack is:
+ * channel_process_cell()
+ * -> chan->cell_handler()
+ *
+ * This test is about checking if we can process an inbound cell down to the
+ * channel handler. */
static void
-test_channel_incoming(void *arg)
+test_channel_inbound_cell(void *arg)
{
- channel_t *ch = NULL;
+ channel_t *chan = NULL;
cell_t *cell = NULL;
- var_cell_t *var_cell = NULL;
int old_count;
- (void)arg;
+ (void) arg;
- /* Mock these for duration of the test */
- MOCK(scheduler_channel_doesnt_want_writes,
- scheduler_channel_doesnt_want_writes_mock);
- MOCK(scheduler_release_channel,
- scheduler_release_channel_mock);
+ /* The channel will be freed so we need to hijack this so the scheduler
+ * doesn't get confused. */
+ MOCK(scheduler_release_channel, scheduler_release_channel_mock);
/* Accept cells to lower layer */
test_chan_accept_cells = 1;
1
0
commit 7ca5f4bf0365b853cdb0bab5cc9cb0ce6deaec26
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Dec 8 10:29:01 2017 -0500
document our allocator conventions
---
doc/HACKING/CodingStandards.md | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/doc/HACKING/CodingStandards.md b/doc/HACKING/CodingStandards.md
index dd21d6fd2..4b1bf4718 100644
--- a/doc/HACKING/CodingStandards.md
+++ b/doc/HACKING/CodingStandards.md
@@ -346,6 +346,46 @@ macro, as in:
if (BUG(ptr == NULL))
return -1;
+Allocator conventions
+---------------------
+
+By convention, any tor type with a name like `abc_t` should be allocated
+by a function named `abc_new()`. This function should never return
+NULL.
+
+Also, a type named `abc_t` should be freed by a function named `abc_free_()`.
+Don't call this `abc_free_()` function directly -- instead, wrap it in a
+macro called `abc_free()`, using the `FREE_AND_NULL` macro:
+
+ void abc_free_(abc_t *obj);
+ #define abc_free(obj) FREE_AND_NULL(abc_t, abc_free_, (abc))
+
+This macro will free the underlying `abc_t` object, and will also set
+the object pointer to NULL.
+
+You should define all `abc_free_()` functions to accept NULL inputs:
+
+ void
+ abc_free_(abc_t *obj)
+ {
+ if (!obj)
+ return;
+ tor_free(obj->name);
+ thing_free(obj->thing);
+ tor_free(obj);
+ }
+
+If you need a free function that takes a `void *` argument (for example,
+to use it as a function callback), define it with a name like
+`abc_free_void()`:
+
+ static void
+ abc_free_void_(void *obj)
+ {
+ abc_free_(obj);
+ }
+
+
Doxygen comment conventions
---------------------------
1
0

[tor/master] Convert remaining function (mostly static) to new free style
by nickm@torproject.org 08 Dec '17
by nickm@torproject.org 08 Dec '17
08 Dec '17
commit fa0d24286b1dac3959c338f6b76fc15dbe1559e5
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Dec 8 10:21:12 2017 -0500
Convert remaining function (mostly static) to new free style
---
src/common/compat.c | 5 ++++-
src/common/container.c | 13 ++++++++++---
src/common/log.c | 5 ++++-
src/common/sandbox.c | 6 +++++-
src/common/workqueue.c | 5 ++++-
src/or/addressmap.c | 35 +++++++++++++++++++++++-----------
src/or/bridges.c | 7 +++++--
src/or/channel.c | 27 +++++++++++++-------------
src/or/channel.h | 2 +-
src/or/config.c | 4 ++--
src/or/config.h | 8 ++++++--
src/or/consdiffmgr.c | 17 ++++++++++++++---
src/or/control.c | 5 ++++-
src/or/cpuworker.c | 19 +++++++++++++++----
src/or/dircollate.c | 5 ++++-
src/or/dirvote.c | 5 ++++-
src/or/entrynodes.c | 4 ++--
src/or/entrynodes.h | 9 +++++++--
src/or/ext_orport.c | 2 +-
src/or/ext_orport.h | 6 +++++-
src/or/geoip.c | 5 ++++-
src/or/hs_cache.c | 44 +++++++++++++++++++++++++++----------------
src/or/hs_circuitmap.c | 5 ++++-
src/or/nodelist.c | 6 ++++--
src/or/rendclient.c | 14 +++++++++-----
src/or/rendservice.c | 4 ++--
src/or/rephist.c | 20 +++++++++++++-------
src/or/routerlist.c | 18 +++++++++++++-----
src/or/scheduler_kist.c | 4 ++--
src/or/shared_random.c | 2 +-
src/or/shared_random_state.c | 12 +++++++++---
src/or/shared_random_state.h | 2 +-
src/test/test_channel.c | 4 ++--
src/test/test_shared_random.c | 2 +-
34 files changed, 227 insertions(+), 104 deletions(-)
diff --git a/src/common/compat.c b/src/common/compat.c
index 38693b21f..b4bd6eba0 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -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;
diff --git a/src/common/container.c b/src/common/container.c
index a6e3c11f3..54b0b2028 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -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);
}
diff --git a/src/common/log.c b/src/common/log.c
index 9d4219be1..80055fda0 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -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;
diff --git a/src/common/sandbox.c b/src/common/sandbox.c
index 8cb78bd28..31beaa341 100644
--- a/src/common/sandbox.c
+++ b/src/common/sandbox.c
@@ -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;
diff --git a/src/common/workqueue.c b/src/common/workqueue.c
index 42723224d..ec96959b7 100644
--- a/src/common/workqueue.c
+++ b/src/common/workqueue.c
@@ -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;
diff --git a/src/or/addressmap.c b/src/or/addressmap.c
index 9a2cc26b3..96ce27557 100644
--- a/src/or/addressmap.c
+++ b/src/or/addressmap.c
@@ -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;
}
diff --git a/src/or/bridges.c b/src/or/bridges.c
index 320f5ee63..f6e3e419d 100644
--- a/src/or/bridges.c
+++ b/src/or/bridges.c
@@ -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;
diff --git a/src/or/channel.c b/src/or/channel.c
index a9e081795..90536b146 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -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);
}
diff --git a/src/or/channel.h b/src/or/channel.h
index 9c631c15a..909813cee 100644
--- a/src/or/channel.h
+++ b/src/or/channel.h
@@ -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);
diff --git a/src/or/config.c b/src/or/config.c
index b32576ccc..a3dc78342 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -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);
}
diff --git a/src/or/config.h b/src/or/config.h
index 8c9796b4c..fe15d0c12 100644
--- a/src/or/config.h
+++ b/src/or/config.h
@@ -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,
diff --git a/src/or/consdiffmgr.c b/src/or/consdiffmgr.c
index 1d63d5957..d7c637574 100644
--- a/src/or/consdiffmgr.c
+++ b/src/or/consdiffmgr.c
@@ -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;
diff --git a/src/or/control.c b/src/or/control.c
index 0d462b2d7..da3831225 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -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;
diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c
index d9371b344..9bec04d79 100644
--- a/src/or/cpuworker.c
+++ b/src/or/cpuworker.c
@@ -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.");
}
diff --git a/src/or/dircollate.c b/src/or/dircollate.c
index 64226724b..ce4534ff6 100644
--- a/src/or/dircollate.c
+++ b/src/or/dircollate.c
@@ -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);
}
diff --git a/src/or/dirvote.c b/src/or/dirvote.c
index 0f8dff626..31b90d63c 100644
--- a/src/or/dirvote.c
+++ b/src/or/dirvote.c
@@ -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;
diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c
index 244a01b5d..016591f88 100644
--- a/src/or/entrynodes.c
+++ b/src/or/entrynodes.c
@@ -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;
diff --git a/src/or/entrynodes.h b/src/or/entrynodes.h
index f2c8d35bf..b5437bae6 100644
--- a/src/or/entrynodes.h
+++ b/src/or/entrynodes.h
@@ -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);
/**
diff --git a/src/or/ext_orport.c b/src/or/ext_orport.c
index 28377a3f3..16a250fa5 100644
--- a/src/or/ext_orport.c
+++ b/src/or/ext_orport.c
@@ -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);
}
diff --git a/src/or/ext_orport.h b/src/or/ext_orport.h
index af2b97e77..09acbc407 100644
--- a/src/or/ext_orport.h
+++ b/src/or/ext_orport.h
@@ -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);
diff --git a/src/or/geoip.c b/src/or/geoip.c
index c976b8d27..d7411e6aa 100644
--- a/src/or/geoip.c
+++ b/src/or/geoip.c
@@ -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;
diff --git a/src/or/hs_cache.c b/src/or/hs_cache.c
index 3ebe13fb4..3c253e21b 100644
--- a/src/or/hs_cache.c
+++ b/src/or/hs_cache.c
@@ -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;
}
diff --git a/src/or/hs_circuitmap.c b/src/or/hs_circuitmap.c
index 97d6053e9..e3d364d7c 100644
--- a/src/or/hs_circuitmap.c
+++ b/src/or/hs_circuitmap.c
@@ -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;
diff --git a/src/or/nodelist.c b/src/or/nodelist.c
index 1ab385cd3..e6eaefb21 100644
--- a/src/or/nodelist.c
+++ b/src/or/nodelist.c
@@ -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;
diff --git a/src/or/rendclient.c b/src/or/rendclient.c
index 327481924..81bd02763 100644
--- a/src/or/rendclient.c
+++ b/src/or/rendclient.c
@@ -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;
}
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index 3e318f73f..600953d4b 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -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));
diff --git a/src/or/rephist.c b/src/or/rephist.c
index 51e800bc3..976c41a69 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -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,
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 0236761eb..ba71b8669 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -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;
diff --git a/src/or/scheduler_kist.c b/src/or/scheduler_kist.c
index d1726ba34..c887f1399 100644
--- a/src/or/scheduler_kist.c
+++ b/src/or/scheduler_kist.c
@@ -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,
diff --git a/src/or/shared_random.c b/src/or/shared_random.c
index 72a7aae13..7723ad461 100644
--- a/src/or/shared_random.c
+++ b/src/or/shared_random.c
@@ -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
diff --git a/src/or/shared_random_state.c b/src/or/shared_random_state.c
index 8c5a497bb..d6109b2de 100644
--- a/src/or/shared_random_state.c
+++ b/src/or/shared_random_state.c
@@ -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);
diff --git a/src/or/shared_random_state.h b/src/or/shared_random_state.h
index 866725c43..fdbbf4919 100644
--- a/src/or/shared_random_state.h
+++ b/src/or/shared_random_state.h
@@ -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);
diff --git a/src/test/test_channel.c b/src/test/test_channel.c
index 023c2950c..594372693 100644
--- a/src/test/test_channel.c
+++ b/src/test/test_channel.c
@@ -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);
diff --git a/src/test/test_shared_random.c b/src/test/test_shared_random.c
index b0278e8a1..96494904e 100644
--- a/src/test/test_shared_random.c
+++ b/src/test/test_shared_random.c
@@ -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);
}
1
0

08 Dec '17
commit e1c29a769cfc6258a8a63e00b30285aacad9124d
Author: David Goulet <dgoulet(a)torproject.org>
Date: Mon Nov 20 16:49:51 2017 -0500
channel: Remove everything related to queue size
The channel subsystem was doing a whole lot to track and try to predict the
channel queue size but they are gone due to previous commit.
Signed-off-by: David Goulet <dgoulet(a)torproject.org>
---
src/or/channel.c | 202 -------------------------------------
src/or/connection_or.c | 3 -
src/test/test_channel.c | 259 ------------------------------------------------
3 files changed, 464 deletions(-)
diff --git a/src/or/channel.c b/src/or/channel.c
index 6f6bd8a7e..0586c05da 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -112,59 +112,6 @@ HANDLE_IMPL(channel, channel_s,)
/* Counter for ID numbers */
static uint64_t n_channels_allocated = 0;
-/*
- * Channel global byte/cell counters, for statistics and for scheduler high
- * /low-water marks.
- */
-
-/*
- * Total number of cells ever given to any channel with the
- * channel_write_*_cell() functions.
- */
-
-static uint64_t n_channel_cells_queued = 0;
-
-/*
- * Total number of cells ever passed to a channel lower layer with the
- * write_*_cell() methods.
- */
-
-static uint64_t n_channel_cells_passed_to_lower_layer = 0;
-
-/*
- * Current number of cells in all channel queues; should be
- * n_channel_cells_queued - n_channel_cells_passed_to_lower_layer.
- */
-
-static uint64_t n_channel_cells_in_queues = 0;
-
-/*
- * Total number of bytes for all cells ever queued to a channel and
- * counted in n_channel_cells_queued.
- */
-
-static uint64_t n_channel_bytes_queued = 0;
-
-/*
- * Total number of bytes for all cells ever passed to a channel lower layer
- * and counted in n_channel_cells_passed_to_lower_layer.
- */
-
-static uint64_t n_channel_bytes_passed_to_lower_layer = 0;
-
-/*
- * Current number of bytes in all channel queues; should be
- * n_channel_bytes_queued - n_channel_bytes_passed_to_lower_layer.
- */
-
-static uint64_t n_channel_bytes_in_queues = 0;
-
-/*
- * Current total estimated queue size *including lower layer queues and
- * transmit overhead*
- */
-
-STATIC uint64_t estimated_total_queue_size = 0;
/* Digest->channel map
*
@@ -204,8 +151,6 @@ HT_GENERATE2(channel_idmap, channel_idmap_entry_s, node, channel_idmap_hash,
static int is_destroy_cell(channel_t *chan,
const cell_queue_entry_t *q, circid_t *circid_out);
-static void channel_assert_counter_consistency(void);
-
/* Functions to maintain the digest map */
static void channel_add_to_digest_map(channel_t *chan);
static void channel_remove_from_digest_map(channel_t *chan);
@@ -1774,12 +1719,6 @@ channel_write_cell_queue_entry(channel_t *chan, cell_queue_entry_t *q)
/* Update the counter */
++(chan->n_cells_xmitted);
chan->n_bytes_xmitted += cell_bytes;
- /* Update global counters */
- ++n_channel_cells_queued;
- ++n_channel_cells_passed_to_lower_layer;
- n_channel_bytes_queued += cell_bytes;
- n_channel_bytes_passed_to_lower_layer += cell_bytes;
- channel_assert_counter_consistency();
}
}
@@ -1816,8 +1755,6 @@ channel_write_cell_generic_(channel_t *chan, const char *cell_type,
cell, chan, U64_PRINTF_ARG(chan->global_identifier));
channel_write_cell_queue_entry(chan, q);
- /* Update the queue size estimate */
- channel_update_xmit_queue_size(chan);
}
/**
@@ -1977,29 +1914,6 @@ channel_change_state_(channel_t *chan, channel_state_t to_state)
} else if (to_state == CHANNEL_STATE_MAINT) {
scheduler_channel_doesnt_want_writes(chan);
}
-
- /*
- * If we're closing, this channel no longer counts toward the global
- * estimated queue size; if we're open, it now does.
- */
- if ((to_state == CHANNEL_STATE_CLOSING ||
- to_state == CHANNEL_STATE_CLOSED ||
- to_state == CHANNEL_STATE_ERROR) &&
- (from_state == CHANNEL_STATE_OPEN ||
- from_state == CHANNEL_STATE_MAINT)) {
- estimated_total_queue_size -= chan->bytes_in_queue;
- }
-
- /*
- * If we're opening, this channel now does count toward the global
- * estimated queue size.
- */
- if ((to_state == CHANNEL_STATE_OPEN ||
- to_state == CHANNEL_STATE_MAINT) &&
- !(from_state == CHANNEL_STATE_OPEN ||
- from_state == CHANNEL_STATE_MAINT)) {
- estimated_total_queue_size += chan->bytes_in_queue;
- }
}
/**
@@ -2438,19 +2352,6 @@ packed_cell_is_destroy(channel_t *chan,
return 0;
}
-/**
- * Assert that the global channel stats counters are internally consistent
- */
-
-static void
-channel_assert_counter_consistency(void)
-{
- tor_assert(n_channel_cells_queued ==
- (n_channel_cells_in_queues + n_channel_cells_passed_to_lower_layer));
- tor_assert(n_channel_bytes_queued ==
- (n_channel_bytes_in_queues + n_channel_bytes_passed_to_lower_layer));
-}
-
/* DOCDOC */
static int
is_destroy_cell(channel_t *chan,
@@ -2530,19 +2431,6 @@ channel_dumpstats(int severity)
{
if (all_channels && smartlist_len(all_channels) > 0) {
tor_log(severity, LD_GENERAL,
- "Channels have queued " U64_FORMAT " bytes in " U64_FORMAT " cells, "
- "and handed " U64_FORMAT " bytes in " U64_FORMAT " cells to the lower"
- " layer.",
- U64_PRINTF_ARG(n_channel_bytes_queued),
- U64_PRINTF_ARG(n_channel_cells_queued),
- U64_PRINTF_ARG(n_channel_bytes_passed_to_lower_layer),
- U64_PRINTF_ARG(n_channel_cells_passed_to_lower_layer));
- tor_log(severity, LD_GENERAL,
- "There are currently " U64_FORMAT " bytes in " U64_FORMAT " cells "
- "in channel queues.",
- U64_PRINTF_ARG(n_channel_bytes_in_queues),
- U64_PRINTF_ARG(n_channel_cells_in_queues));
- tor_log(severity, LD_GENERAL,
"Dumping statistics about %d channels:",
smartlist_len(all_channels));
tor_log(severity, LD_GENERAL,
@@ -3641,16 +3529,6 @@ channel_mark_outgoing(channel_t *chan)
***********************/
/*
- * Get the latest estimate for the total queue size of all open channels
- */
-
-uint64_t
-channel_get_global_queue_estimate(void)
-{
- return estimated_total_queue_size;
-}
-
-/*
* Estimate the number of writeable cells
*
* Ask the lower layer for an estimate of how many cells it can accept.
@@ -4163,83 +4041,3 @@ channel_update_bad_for_new_circs(const char *digest, int force)
}
}
-/**
- * Update the estimated number of bytes queued to transmit for this channel,
- * and notify the scheduler. The estimate includes both the channel queue and
- * the queue size reported by the lower layer, and an overhead estimate
- * optionally provided by the lower layer.
- */
-
-void
-channel_update_xmit_queue_size(channel_t *chan)
-{
- uint64_t queued, adj;
- double overhead;
-
- tor_assert(chan);
- tor_assert(chan->num_bytes_queued);
-
- /*
- * First, get the number of bytes we have queued without factoring in
- * lower-layer overhead.
- */
- queued = chan->num_bytes_queued(chan) + chan->bytes_in_queue;
- /* Next, adjust by the overhead factor, if any is available */
- if (chan->get_overhead_estimate) {
- overhead = chan->get_overhead_estimate(chan);
- if (overhead >= 1.0) {
- queued = (uint64_t)(queued * overhead);
- } else {
- /* Ignore silly overhead factors */
- log_notice(LD_CHANNEL, "Ignoring silly overhead factor %f", overhead);
- }
- }
-
- /* Now, compare to the previous estimate */
- if (queued > chan->bytes_queued_for_xmit) {
- adj = queued - chan->bytes_queued_for_xmit;
- log_debug(LD_CHANNEL,
- "Increasing queue size for channel " U64_FORMAT " by " U64_FORMAT
- " from " U64_FORMAT " to " U64_FORMAT,
- U64_PRINTF_ARG(chan->global_identifier),
- U64_PRINTF_ARG(adj),
- U64_PRINTF_ARG(chan->bytes_queued_for_xmit),
- U64_PRINTF_ARG(queued));
- /* Update the channel's estimate */
- chan->bytes_queued_for_xmit = queued;
-
- /* Update the global queue size estimate if appropriate */
- if (chan->state == CHANNEL_STATE_OPEN ||
- chan->state == CHANNEL_STATE_MAINT) {
- estimated_total_queue_size += adj;
- log_debug(LD_CHANNEL,
- "Increasing global queue size by " U64_FORMAT " for channel "
- U64_FORMAT ", new size is " U64_FORMAT,
- U64_PRINTF_ARG(adj), U64_PRINTF_ARG(chan->global_identifier),
- U64_PRINTF_ARG(estimated_total_queue_size));
- }
- } else if (queued < chan->bytes_queued_for_xmit) {
- adj = chan->bytes_queued_for_xmit - queued;
- log_debug(LD_CHANNEL,
- "Decreasing queue size for channel " U64_FORMAT " by " U64_FORMAT
- " from " U64_FORMAT " to " U64_FORMAT,
- U64_PRINTF_ARG(chan->global_identifier),
- U64_PRINTF_ARG(adj),
- U64_PRINTF_ARG(chan->bytes_queued_for_xmit),
- U64_PRINTF_ARG(queued));
- /* Update the channel's estimate */
- chan->bytes_queued_for_xmit = queued;
-
- /* Update the global queue size estimate if appropriate */
- if (chan->state == CHANNEL_STATE_OPEN ||
- chan->state == CHANNEL_STATE_MAINT) {
- estimated_total_queue_size -= adj;
- log_debug(LD_CHANNEL,
- "Decreasing global queue size by " U64_FORMAT " for channel "
- U64_FORMAT ", new size is " U64_FORMAT,
- U64_PRINTF_ARG(adj), U64_PRINTF_ARG(chan->global_identifier),
- U64_PRINTF_ARG(estimated_total_queue_size));
- }
- }
-}
-
diff --git a/src/or/connection_or.c b/src/or/connection_or.c
index 7af1f2b64..268b3d984 100644
--- a/src/or/connection_or.c
+++ b/src/or/connection_or.c
@@ -592,9 +592,6 @@ connection_or_flushed_some(or_connection_t *conn)
{
size_t datalen;
- /* The channel will want to update its estimated queue size */
- channel_update_xmit_queue_size(TLS_CHAN_TO_BASE(conn->chan));
-
/* If we're under the low water mark, add cells until we're just over the
* high water mark. */
datalen = connection_get_outbuf_len(TO_CONN(conn));
diff --git a/src/test/test_channel.c b/src/test/test_channel.c
index 28f84825c..3381a5c7d 100644
--- a/src/test/test_channel.c
+++ b/src/test/test_channel.c
@@ -61,8 +61,6 @@ static void scheduler_channel_doesnt_want_writes_mock(channel_t *ch);
static void test_channel_dumpstats(void *arg);
static void test_channel_incoming(void *arg);
static void test_channel_lifecycle(void *arg);
-static void test_channel_multi(void *arg);
-static void test_channel_queue_size(void *arg);
static void test_channel_write(void *arg);
static void
@@ -918,261 +916,6 @@ test_channel_lifecycle_2(void *arg)
}
static void
-test_channel_multi(void *arg)
-{
- channel_t *ch1 = NULL, *ch2 = NULL;
- uint64_t global_queue_estimate;
- cell_t *cell = NULL;
-
- (void)arg;
-
- /* Accept cells to lower layer */
- test_chan_accept_cells = 1;
- /* Use default overhead factor */
- test_overhead_estimate = 1.0;
-
- ch1 = new_fake_channel();
- tt_assert(ch1);
- ch2 = new_fake_channel();
- tt_assert(ch2);
-
- /* Initial queue size update */
- channel_update_xmit_queue_size(ch1);
- tt_u64_op(ch1->bytes_queued_for_xmit, OP_EQ, 0);
- channel_update_xmit_queue_size(ch2);
- tt_u64_op(ch2->bytes_queued_for_xmit, OP_EQ, 0);
- global_queue_estimate = channel_get_global_queue_estimate();
- tt_u64_op(global_queue_estimate, OP_EQ, 0);
-
- /* Queue some cells, check queue estimates */
- cell = tor_malloc_zero(sizeof(cell_t));
- make_fake_cell(cell);
- channel_write_cell(ch1, cell);
-
- cell = tor_malloc_zero(sizeof(cell_t));
- make_fake_cell(cell);
- channel_write_cell(ch2, cell);
-
- channel_update_xmit_queue_size(ch1);
- channel_update_xmit_queue_size(ch2);
- tt_u64_op(ch1->bytes_queued_for_xmit, OP_EQ, 0);
- tt_u64_op(ch2->bytes_queued_for_xmit, OP_EQ, 0);
- global_queue_estimate = channel_get_global_queue_estimate();
- tt_u64_op(global_queue_estimate, OP_EQ, 0);
-
- /* Stop accepting cells at lower layer */
- test_chan_accept_cells = 0;
-
- /* Queue some cells and check queue estimates */
- cell = tor_malloc_zero(sizeof(cell_t));
- make_fake_cell(cell);
- channel_write_cell(ch1, cell);
-
- channel_update_xmit_queue_size(ch1);
- tt_u64_op(ch1->bytes_queued_for_xmit, OP_EQ, 512);
- global_queue_estimate = channel_get_global_queue_estimate();
- tt_u64_op(global_queue_estimate, OP_EQ, 512);
-
- cell = tor_malloc_zero(sizeof(cell_t));
- make_fake_cell(cell);
- channel_write_cell(ch2, cell);
-
- channel_update_xmit_queue_size(ch2);
- tt_u64_op(ch2->bytes_queued_for_xmit, OP_EQ, 512);
- global_queue_estimate = channel_get_global_queue_estimate();
- tt_u64_op(global_queue_estimate, OP_EQ, 1024);
-
- /* Allow cells through again */
- test_chan_accept_cells = 1;
-
- /* Update and check queue sizes */
- channel_update_xmit_queue_size(ch1);
- channel_update_xmit_queue_size(ch2);
- tt_u64_op(ch1->bytes_queued_for_xmit, OP_EQ, 512);
- tt_u64_op(ch2->bytes_queued_for_xmit, OP_EQ, 0);
- global_queue_estimate = channel_get_global_queue_estimate();
- tt_u64_op(global_queue_estimate, OP_EQ, 512);
-
- /* Update and check queue sizes */
- channel_update_xmit_queue_size(ch1);
- channel_update_xmit_queue_size(ch2);
- tt_u64_op(ch1->bytes_queued_for_xmit, OP_EQ, 0);
- tt_u64_op(ch2->bytes_queued_for_xmit, OP_EQ, 0);
- global_queue_estimate = channel_get_global_queue_estimate();
- tt_u64_op(global_queue_estimate, OP_EQ, 0);
-
- /* Now block again */
- test_chan_accept_cells = 0;
-
- /* Queue some cells */
- cell = tor_malloc_zero(sizeof(cell_t));
- make_fake_cell(cell);
- channel_write_cell(ch1, cell);
-
- cell = tor_malloc_zero(sizeof(cell_t));
- make_fake_cell(cell);
- channel_write_cell(ch2, cell);
- cell = NULL;
-
- /* Check the estimates */
- channel_update_xmit_queue_size(ch1);
- channel_update_xmit_queue_size(ch2);
- tt_u64_op(ch1->bytes_queued_for_xmit, OP_EQ, 512);
- tt_u64_op(ch2->bytes_queued_for_xmit, OP_EQ, 512);
- global_queue_estimate = channel_get_global_queue_estimate();
- tt_u64_op(global_queue_estimate, OP_EQ, 1024);
-
- /* Now close channel 2; it should be subtracted from the global queue */
- MOCK(scheduler_release_channel, scheduler_release_channel_mock);
- channel_mark_for_close(ch2);
- UNMOCK(scheduler_release_channel);
-
- global_queue_estimate = channel_get_global_queue_estimate();
- tt_u64_op(global_queue_estimate, OP_EQ, 512);
-
- /*
- * Since the fake channels aren't registered, channel_free_all() can't
- * see them properly.
- */
- MOCK(scheduler_release_channel, scheduler_release_channel_mock);
- channel_mark_for_close(ch1);
- UNMOCK(scheduler_release_channel);
-
- global_queue_estimate = channel_get_global_queue_estimate();
- tt_u64_op(global_queue_estimate, OP_EQ, 0);
-
- /* Now free everything */
- MOCK(scheduler_release_channel, scheduler_release_channel_mock);
- channel_free_all();
- UNMOCK(scheduler_release_channel);
-
- done:
- free_fake_channel(ch1);
- free_fake_channel(ch2);
-
- return;
-}
-
-static void
-test_channel_queue_size(void *arg)
-{
- channel_t *ch = NULL;
- cell_t *cell = NULL;
- int n, old_count;
- uint64_t global_queue_estimate;
-
- (void)arg;
-
- ch = new_fake_channel();
- tt_assert(ch);
-
- /* Initial queue size update */
- channel_update_xmit_queue_size(ch);
- tt_u64_op(ch->bytes_queued_for_xmit, OP_EQ, 0);
- global_queue_estimate = channel_get_global_queue_estimate();
- tt_u64_op(global_queue_estimate, OP_EQ, 0);
-
- /* Test the call-through to our fake lower layer */
- n = channel_num_cells_writeable(ch);
- /* chan_test_num_cells_writeable() always returns 32 */
- tt_int_op(n, OP_EQ, 32);
-
- /*
- * Now we queue some cells and check that channel_num_cells_writeable()
- * adjusts properly
- */
-
- /* tell it not to accept cells */
- test_chan_accept_cells = 0;
- /* ...and keep it from trying to flush the queue */
- ch->state = CHANNEL_STATE_MAINT;
-
- /* Get a fresh cell */
- cell = tor_malloc_zero(sizeof(cell_t));
- make_fake_cell(cell);
-
- old_count = test_cells_written;
- channel_write_cell(ch, cell);
- /* Assert that it got queued, not written through, correctly */
- tt_int_op(test_cells_written, OP_EQ, old_count);
-
- /* Now check chan_test_num_cells_writeable() again */
- n = channel_num_cells_writeable(ch);
- /* Should return 0 since we're in CHANNEL_STATE_MAINT */
- tt_int_op(n, OP_EQ, 0);
-
- /* Update queue size estimates */
- channel_update_xmit_queue_size(ch);
- /* One cell, times an overhead factor of 1.0 */
- tt_u64_op(ch->bytes_queued_for_xmit, OP_EQ, 512);
- /* Try a different overhead factor */
- test_overhead_estimate = 0.5;
- /* This one should be ignored since it's below 1.0 */
- channel_update_xmit_queue_size(ch);
- tt_u64_op(ch->bytes_queued_for_xmit, OP_EQ, 512);
- /* Now try a larger one */
- test_overhead_estimate = 2.0;
- channel_update_xmit_queue_size(ch);
- tt_u64_op(ch->bytes_queued_for_xmit, OP_EQ, 1024);
- /* Go back to 1.0 */
- test_overhead_estimate = 1.0;
- channel_update_xmit_queue_size(ch);
- tt_u64_op(ch->bytes_queued_for_xmit, OP_EQ, 512);
- /* Check the global estimate too */
- global_queue_estimate = channel_get_global_queue_estimate();
- tt_u64_op(global_queue_estimate, OP_EQ, 512);
-
- /* Go to open */
- old_count = test_cells_written;
- channel_change_state_open(ch);
-
- /*
- * It should try to write, but we aren't accepting cells right now, so
- * it'll requeue
- */
- tt_int_op(test_cells_written, OP_EQ, old_count);
-
- /* Check the queue size again */
- channel_update_xmit_queue_size(ch);
- tt_u64_op(ch->bytes_queued_for_xmit, OP_EQ, 512);
- global_queue_estimate = channel_get_global_queue_estimate();
- tt_u64_op(global_queue_estimate, OP_EQ, 512);
-
- /*
- * Now the cell is in the queue, and we're open, so we should get 31
- * writeable cells.
- */
- n = channel_num_cells_writeable(ch);
- tt_int_op(n, OP_EQ, 31);
-
- /* Accept cells again */
- test_chan_accept_cells = 1;
- /* ...and re-process the queue */
- old_count = test_cells_written;
- tt_int_op(test_cells_written, OP_EQ, old_count + 1);
-
- /* Should have 32 writeable now */
- n = channel_num_cells_writeable(ch);
- tt_int_op(n, OP_EQ, 32);
-
- /* Should have queue size estimate of zero */
- channel_update_xmit_queue_size(ch);
- tt_u64_op(ch->bytes_queued_for_xmit, OP_EQ, 0);
- global_queue_estimate = channel_get_global_queue_estimate();
- tt_u64_op(global_queue_estimate, OP_EQ, 0);
-
- /* Okay, now we're done with this one */
- MOCK(scheduler_release_channel, scheduler_release_channel_mock);
- channel_mark_for_close(ch);
- UNMOCK(scheduler_release_channel);
-
- done:
- free_fake_channel(ch);
-
- return;
-}
-
-static void
test_channel_write(void *arg)
{
channel_t *ch = NULL;
@@ -1399,8 +1142,6 @@ struct testcase_t channel_tests[] = {
{ "incoming", test_channel_incoming, TT_FORK, NULL, NULL },
{ "lifecycle", test_channel_lifecycle, TT_FORK, NULL, NULL },
{ "lifecycle_2", test_channel_lifecycle_2, TT_FORK, NULL, NULL },
- { "multi", test_channel_multi, TT_FORK, NULL, NULL },
- { "queue_size", test_channel_queue_size, TT_FORK, NULL, NULL },
{ "write", test_channel_write, TT_FORK, NULL, NULL },
{ "id_map", test_channel_id_map, TT_FORK, NULL, NULL },
END_OF_TESTCASES
1
0