tor-commits
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- 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
- 2423 discussions
[tor/master] Fix up test_circuitstats to use the new circuit_free macro
by nickm@torproject.org 08 Dec '17
by nickm@torproject.org 08 Dec '17
08 Dec '17
commit 241b676638285e63bd6e4ca5225444a4b16207be
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Dec 8 17:52:45 2017 -0500
Fix up test_circuitstats to use the new circuit_free macro
---
src/test/test_circuitstats.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/test/test_circuitstats.c b/src/test/test_circuitstats.c
index 1c6a2ba28..9d87c325b 100644
--- a/src/test/test_circuitstats.c
+++ b/src/test/test_circuitstats.c
@@ -3,6 +3,7 @@
#define CIRCUITBUILD_PRIVATE
#define CIRCUITSTATS_PRIVATE
+#define CIRCUITLIST_PRIVATE
#define CHANNEL_PRIVATE_
#include "or.h"
@@ -22,7 +23,6 @@ origin_circuit_t *subtest_fourhop_circuit(struct timeval, int);
origin_circuit_t *add_opened_threehop(void);
origin_circuit_t *build_unopened_fourhop(struct timeval);
-void circuit_free(circuit_t *circ);
int onion_append_hop(crypt_path_t **head_ptr, extend_info_t *choice);
static int marked_for_close;
@@ -153,7 +153,7 @@ test_circuitstats_hoplen(void *arg)
tt_int_op(get_circuit_build_times()->total_build_times, OP_EQ, 1);
tt_int_op(marked_for_close, OP_EQ, 1);
- circuit_free(TO_CIRCUIT(fourhop));
+ circuit_free_(TO_CIRCUIT(fourhop));
circuit_build_times_reset(get_circuit_build_times_mutable());
// Test 2: Add a threehop circuit for non-relaxed timeouts
@@ -168,7 +168,7 @@ test_circuitstats_hoplen(void *arg)
tt_int_op(TO_CIRCUIT(fourhop)->purpose, OP_NE,
CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT);
- circuit_free((circuit_t *)fourhop);
+ circuit_free_((circuit_t *)fourhop);
circuit_build_times_reset(get_circuit_build_times_mutable());
/* Test 3: This circuit should now time out and get marked as a
@@ -184,8 +184,8 @@ test_circuitstats_hoplen(void *arg)
done:
UNMOCK(circuit_mark_for_close_);
- circuit_free(TO_CIRCUIT(threehop));
- circuit_free(TO_CIRCUIT(fourhop));
+ circuit_free_(TO_CIRCUIT(threehop));
+ circuit_free_(TO_CIRCUIT(fourhop));
circuit_build_times_free_timeouts(get_circuit_build_times_mutable());
}
1
0
08 Dec '17
commit b5d4cd1b4178bfa285fc5c512a29daa2580d96b8
Author: Mike Perry <mikeperry-git(a)torproject.org>
Date: Fri Aug 4 17:16:38 2017 -0400
Bug #23100: Count all 3 hop circuits for CBT.
This change causes us to count anything once it reaches 3 hops (but not
after).
---
changes/bug23100 | 7 +++++
src/or/circuitbuild.c | 55 +++++++++++------------------------
src/or/circuitbuild.h | 2 +-
src/or/circuitlist.c | 19 +++++++++++++
src/or/circuitlist.h | 1 +
src/or/circuitstats.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++-
src/or/circuitstats.h | 1 +
7 files changed, 124 insertions(+), 40 deletions(-)
diff --git a/changes/bug23100 b/changes/bug23100
new file mode 100644
index 000000000..22e2485d6
--- /dev/null
+++ b/changes/bug23100
@@ -0,0 +1,7 @@
+ o Minor bugfixes (Performance):
+ - Use hidden service circuits (and other circuits longer than 3 hops)
+ to calculate a circuit build timeout. Previously, Tor only calculated
+ its build timeout based on circuits that planned to be exactly 3 hops
+ long. With this change, we include measurements from all circuits at
+ the point where they complete their third hop. Fixes bug 23100;
+ bugfix on 0.2.2.2-alpha.
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index b36fed63b..0be54c533 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -825,16 +825,25 @@ should_use_create_fast_for_circuit(origin_circuit_t *circ)
return networkstatus_get_param(NULL, "usecreatefast", 0, 0, 1);
}
-/** Return true if <b>circ</b> is the type of circuit we want to count
- * timeouts from. In particular, we want it to have not completed yet
- * (already completing indicates we cannibalized it), and we want it to
- * have exactly three hops.
+/**
+ * Return true if <b>circ</b> is the type of circuit we want to count
+ * timeouts from.
+ *
+ * In particular, we want to consider any circuit that plans to build
+ * at least 3 hops (but maybe more), but has 3 or fewer hops built
+ * so far.
+ *
+ * We still want to consider circuits before 3 hops, because we need
+ * to decide if we should convert them to a measurement circuit in
+ * circuit_build_times_handle_completed_hop(), rather than letting
+ * slow circuits get killed right away.
*/
int
-circuit_timeout_want_to_count_circ(origin_circuit_t *circ)
+circuit_timeout_want_to_count_circ(const origin_circuit_t *circ)
{
return !circ->has_opened
- && circ->build_state->desired_path_len == DEFAULT_ROUTE_LEN;
+ && circ->build_state->desired_path_len >= DEFAULT_ROUTE_LEN
+ && circuit_get_cpath_opened_len(circ) <= DEFAULT_ROUTE_LEN;
}
/** Decide whether to use a TAP or ntor handshake for connecting to <b>ei</b>
@@ -938,7 +947,9 @@ circuit_send_next_onion_skin(origin_circuit_t *circ)
tor_assert(circ->cpath->state == CPATH_STATE_OPEN);
tor_assert(circ->base_.state == CIRCUIT_STATE_BUILDING);
+
crypt_path_t *hop = onion_next_hop_in_cpath(circ->cpath);
+ circuit_build_times_handle_completed_hop(circ);
if (hop) {
/* Case two: we're on a hop after the first. */
@@ -1053,38 +1064,6 @@ circuit_build_no_more_hops(origin_circuit_t *circ)
* I think I got them right, but more checking would be wise. -NM
*/
- if (circuit_timeout_want_to_count_circ(circ)) {
- struct timeval end;
- long timediff;
- tor_gettimeofday(&end);
- timediff = tv_mdiff(&circ->base_.timestamp_began, &end);
-
- /*
- * If the circuit build time is much greater than we would have cut
- * it off at, we probably had a suspend event along this codepath,
- * and we should discard the value.
- */
- if (timediff < 0 ||
- timediff > 2*get_circuit_build_close_time_ms()+1000) {
- log_notice(LD_CIRC, "Strange value for circuit build time: %ldmsec. "
- "Assuming clock jump. Purpose %d (%s)", timediff,
- circ->base_.purpose,
- circuit_purpose_to_string(circ->base_.purpose));
- } else if (!circuit_build_times_disabled(get_options())) {
- /* Only count circuit times if the network is live */
- if (circuit_build_times_network_check_live(
- get_circuit_build_times())) {
- circuit_build_times_add_time(get_circuit_build_times_mutable(),
- (build_time_t)timediff);
- circuit_build_times_set_timeout(get_circuit_build_times_mutable());
- }
-
- if (circ->base_.purpose != CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
- circuit_build_times_network_circ_success(
- get_circuit_build_times_mutable());
- }
- }
- }
log_info(LD_CIRC,"circuit built!");
circuit_reset_failure_count(0);
diff --git a/src/or/circuitbuild.h b/src/or/circuitbuild.h
index b8a651e05..3c28781bc 100644
--- a/src/or/circuitbuild.h
+++ b/src/or/circuitbuild.h
@@ -27,7 +27,7 @@ int circuit_handle_first_hop(origin_circuit_t *circ);
void circuit_n_chan_done(channel_t *chan, int status,
int close_origin_circuits);
int inform_testing_reachability(void);
-int circuit_timeout_want_to_count_circ(origin_circuit_t *circ);
+int circuit_timeout_want_to_count_circ(const origin_circuit_t *circ);
int circuit_send_next_onion_skin(origin_circuit_t *circ);
void circuit_note_clock_jumped(int seconds_elapsed);
int circuit_extend(cell_t *cell, circuit_t *circ);
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index d37d986f1..20fa03306 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -1789,6 +1789,25 @@ circuit_get_cpath_len(origin_circuit_t *circ)
return n;
}
+/** Return the number of opened hops in circuit's path.
+ * If circ has no entries, or is NULL, returns 0. */
+int
+circuit_get_cpath_opened_len(origin_circuit_t *circ)
+{
+ int n = 0;
+ if (circ && circ->cpath) {
+ crypt_path_t *cpath, *cpath_next = NULL;
+ for (cpath = circ->cpath;
+ cpath->state == CPATH_STATE_OPEN
+ && cpath_next != circ->cpath;
+ cpath = cpath_next) {
+ cpath_next = cpath->next;
+ ++n;
+ }
+ }
+ return n;
+}
+
/** Return the <b>hopnum</b>th hop in <b>circ</b>->cpath, or NULL if there
* aren't that many hops in the list. <b>hopnum</b> starts at 1.
* Returns NULL if <b>hopnum</b> is 0 or negative. */
diff --git a/src/or/circuitlist.h b/src/or/circuitlist.h
index 5d0da15ca..c90f5445d 100644
--- a/src/or/circuitlist.h
+++ b/src/or/circuitlist.h
@@ -58,6 +58,7 @@ void circuit_mark_all_dirty_circs_as_unusable(void);
MOCK_DECL(void, circuit_mark_for_close_, (circuit_t *circ, int reason,
int line, const char *file));
int circuit_get_cpath_len(origin_circuit_t *circ);
+int circuit_get_cpath_opened_len(origin_circuit_t *);
void circuit_clear_cpath(origin_circuit_t *circ);
crypt_path_t *circuit_get_cpath_hop(origin_circuit_t *circ, int hopnum);
void circuit_get_all_pending_on_channel(smartlist_t *out,
diff --git a/src/or/circuitstats.c b/src/or/circuitstats.c
index 923a6d794..5cb90c500 100644
--- a/src/or/circuitstats.c
+++ b/src/or/circuitstats.c
@@ -36,6 +36,7 @@
#include "rendclient.h"
#include "rendservice.h"
#include "statefile.h"
+#include "circuitlist.h"
#undef log
#include <math.h>
@@ -611,6 +612,77 @@ circuit_build_times_rewind_history(circuit_build_times_t *cbt, int n)
#endif /* 0 */
/**
+ * Perform the build time work that needs to be done when a circuit
+ * completes a hop.
+ *
+ * This function decides if we should record a circuit's build time
+ * in our histogram data and other statistics, and if so, records it.
+ * It also will mark circuits that have already timed out as
+ * measurement-only circuits, so they can continue to build but
+ * not get used.
+ *
+ * For this, we want to consider circuits that will eventually make
+ * it to the third hop. For circuits longer than 3 hops, we want to
+ * record their build time when they reach the third hop, but let
+ * them continue (and not count them later). For circuits that are
+ * exactly 3 hops, this will count them when they are completed. We
+ * do this so that CBT is always gathering statistics on circuits
+ * of the same length, regardless of their type.
+ */
+void
+circuit_build_times_handle_completed_hop(origin_circuit_t *circ)
+{
+ struct timeval end;
+ long timediff;
+
+ /* If circuit build times are disabled, let circuit_expire_building()
+ * handle it.. */
+ if (circuit_build_times_disabled(get_options())) {
+ return;
+ }
+
+ /* Is this a circuit for which the timeout applies in a straight-forward
+ * way? If so, handle it below. If not, just return (and let
+ * circuit_expire_building() eventually take care of it).
+ */
+ if (!circuit_timeout_want_to_count_circ(circ)) {
+ return;
+ }
+
+ /* If the circuit is built to exactly the DEFAULT_ROUTE_LEN,
+ * add it to our buildtimes. */
+ if (circuit_get_cpath_opened_len(circ) == DEFAULT_ROUTE_LEN) {
+ tor_gettimeofday(&end);
+ timediff = tv_mdiff(&circ->base_.timestamp_began, &end);
+
+ /* If the circuit build time is much greater than we would have cut
+ * it off at, we probably had a suspend event along this codepath,
+ * and we should discard the value.
+ */
+ if (timediff < 0 ||
+ timediff > 2*get_circuit_build_close_time_ms()+1000) {
+ log_notice(LD_CIRC, "Strange value for circuit build time: %ldmsec. "
+ "Assuming clock jump. Purpose %d (%s)", timediff,
+ circ->base_.purpose,
+ circuit_purpose_to_string(circ->base_.purpose));
+ } else {
+ /* Only count circuit times if the network is live */
+ if (circuit_build_times_network_check_live(
+ get_circuit_build_times())) {
+ circuit_build_times_add_time(get_circuit_build_times_mutable(),
+ (build_time_t)timediff);
+ circuit_build_times_set_timeout(get_circuit_build_times_mutable());
+ }
+
+ if (circ->base_.purpose != CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
+ circuit_build_times_network_circ_success(
+ get_circuit_build_times_mutable());
+ }
+ }
+ }
+}
+
+/**
* Add a new build time value <b>time</b> to the set of build times. Time
* units are milliseconds.
*
@@ -1285,9 +1357,14 @@ circuit_build_times_network_is_live(circuit_build_times_t *cbt)
}
/**
- * Called to indicate that we completed a circuit. Because this circuit
+ * Called to indicate that we "completed" a circuit. Because this circuit
* succeeded, it doesn't count as a timeout-after-the-first-hop.
*
+ * (For the purposes of the cbt code, we consider a circuit "completed" if
+ * it has 3 hops, regardless of its final hop count. We do this because
+ * we're trying to answer the question, "how long should a circuit take to
+ * reach the 3-hop count".)
+ *
* This is used by circuit_build_times_network_check_changed() to determine
* if we had too many recent timeouts and need to reset our learned timeout
* to something higher.
diff --git a/src/or/circuitstats.h b/src/or/circuitstats.h
index 92dc6405b..68b66af1b 100644
--- a/src/or/circuitstats.h
+++ b/src/or/circuitstats.h
@@ -34,6 +34,7 @@ void circuit_build_times_set_timeout(circuit_build_times_t *cbt);
int circuit_build_times_add_time(circuit_build_times_t *cbt,
build_time_t time);
int circuit_build_times_needs_circuits(const circuit_build_times_t *cbt);
+void circuit_build_times_handle_completed_hop(origin_circuit_t *circ);
int circuit_build_times_needs_circuits_now(const circuit_build_times_t *cbt);
void circuit_build_times_init(circuit_build_times_t *cbt);
1
0
commit b189c613bb27695753761d0851c17f521e8f00de
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Dec 8 15:11:18 2017 -0500
move a macro; fix a build?
---
src/or/protover.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/or/protover.h b/src/or/protover.h
index 8bbc2fc71..477274e29 100644
--- a/src/or/protover.h
+++ b/src/or/protover.h
@@ -83,11 +83,11 @@ 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);
+#endif /* !defined(HAVE_RUST) && defined(TOR_UNIT_TESTS) */
+
#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) */
1
0
[tor/master] Replace all FREE_AND_NULL* uses to take a type and a free function.
by nickm@torproject.org 08 Dec '17
by nickm@torproject.org 08 Dec '17
08 Dec '17
commit 285632a61b4e4aeec07b26004396473e0d8f4a43
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Thu Dec 7 10:44:04 2017 -0500
Replace all FREE_AND_NULL* uses to take a type and a free function.
This commit was made mechanically by this perl script:
\#!/usr/bin/perl -w -i -p
next if /^#define FREE_AND_NULL/;
s/\bFREE_AND_NULL\((\w+),/FREE_AND_NULL\(${1}_t, ${1}_free_,/;
s/\bFREE_AND_NULL_UNMATCHED\(/FREE_AND_NULL\(/;
---
src/common/address.h | 2 +-
src/common/aes.h | 2 +-
src/common/buffers.h | 2 +-
src/common/compat_libevent.h | 4 ++--
src/common/compat_threads.h | 4 ++--
src/common/compress.h | 2 +-
src/common/compress_lzma.h | 2 +-
src/common/compress_zlib.h | 2 +-
src/common/compress_zstd.h | 2 +-
src/common/container.h | 6 +++---
src/common/crypto.h | 10 +++++-----
src/common/crypto_ed25519.h | 2 +-
src/common/log.c | 2 +-
src/common/procmon.h | 2 +-
src/common/storagedir.h | 2 +-
src/common/timers.h | 2 +-
src/common/tortls.h | 4 ++--
src/common/util.h | 2 +-
src/or/channel.h | 6 +++---
src/or/circuitbuild.h | 2 +-
src/or/circuitlist.h | 2 +-
src/or/circuitmux.h | 2 +-
src/or/config.h | 2 +-
src/or/connection.h | 2 +-
src/or/connection_or.h | 4 ++--
src/or/conscache.h | 4 ++--
src/or/dircollate.h | 2 +-
src/or/directory.h | 2 +-
src/or/dirserv.h | 2 +-
src/or/dirvote.h | 2 +-
src/or/entrynodes.h | 6 +++---
src/or/hs_common.h | 2 +-
src/or/hs_descriptor.h | 10 +++++-----
src/or/hs_ident.h | 6 +++---
src/or/hs_service.h | 6 +++---
src/or/networkstatus.h | 8 ++++----
src/or/onion.h | 2 +-
src/or/onion_fast.h | 2 +-
src/or/onion_ntor.h | 2 +-
src/or/policies.h | 6 +++---
src/or/proto_socks.h | 2 +-
src/or/protover.h | 2 +-
src/or/relay.h | 4 ++--
src/or/rendcache.h | 6 +++---
src/or/rendcommon.h | 6 +++---
src/or/rendservice.h | 6 +++---
src/or/replaycache.h | 2 +-
src/or/router.h | 2 +-
src/or/routerlist.h | 8 ++++----
src/or/routerset.h | 2 +-
src/or/shared_random.h | 2 +-
src/or/statefile.h | 2 +-
src/or/torcert.h | 4 ++--
src/or/transports.h | 2 +-
src/test/test_handles.c | 2 +-
55 files changed, 94 insertions(+), 94 deletions(-)
diff --git a/src/common/address.h b/src/common/address.h
index 6f59e1c96..7607c76ba 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_UNMATCHED(smartlist_t, interface_address6_list_free_, (addrs))
+ FREE_AND_NULL(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 c2720d29b..0b17cd55a 100644
--- a/src/common/aes.h
+++ b/src/common/aes.h
@@ -19,7 +19,7 @@ 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_UNMATCHED(aes_cnt_cipher_t, aes_cipher_free_, (cipher))
+ FREE_AND_NULL(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/buffers.h b/src/common/buffers.h
index 34e9711b2..43a8043b5 100644
--- a/src/common/buffers.h
+++ b/src/common/buffers.h
@@ -25,7 +25,7 @@ buf_t *buf_new(void);
buf_t *buf_new_with_capacity(size_t size);
size_t buf_get_default_chunk_size(const buf_t *buf);
void buf_free_(buf_t *buf);
-#define buf_free(b) FREE_AND_NULL(buf, (b))
+#define buf_free(b) FREE_AND_NULL(buf_t, buf_free_, (b))
void buf_clear(buf_t *buf);
buf_t *buf_copy(const buf_t *buf);
diff --git a/src/common/compat_libevent.h b/src/common/compat_libevent.h
index 2c86194d0..086899ad1 100644
--- a/src/common/compat_libevent.h
+++ b/src/common/compat_libevent.h
@@ -21,7 +21,7 @@ void suppress_libevent_log_msg(const char *msg);
void tor_event_free_(struct event *ev);
#define tor_event_free(ev) \
- FREE_AND_NULL_UNMATCHED(struct event, tor_event_free_, (ev))
+ FREE_AND_NULL(struct event, tor_event_free_, (ev))
typedef struct periodic_timer_t periodic_timer_t;
@@ -30,7 +30,7 @@ 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))
+#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/compat_threads.h b/src/common/compat_threads.h
index 26e291ae6..0f420cb81 100644
--- a/src/common/compat_threads.h
+++ b/src/common/compat_threads.h
@@ -51,7 +51,7 @@ void tor_mutex_init_nonrecursive(tor_mutex_t *m);
void tor_mutex_acquire(tor_mutex_t *m);
void tor_mutex_release(tor_mutex_t *m);
void tor_mutex_free_(tor_mutex_t *m);
-#define tor_mutex_free(m) FREE_AND_NULL(tor_mutex, (m))
+#define tor_mutex_free(m) FREE_AND_NULL(tor_mutex_t, tor_mutex_free_, (m))
void tor_mutex_uninit(tor_mutex_t *m);
unsigned long tor_get_thread_id(void);
void tor_threads_init(void);
@@ -79,7 +79,7 @@ typedef struct tor_cond_t {
tor_cond_t *tor_cond_new(void);
void tor_cond_free_(tor_cond_t *cond);
-#define tor_cond_free(c) FREE_AND_NULL(tor_cond, (c))
+#define tor_cond_free(c) FREE_AND_NULL(tor_cond_t, tor_cond_free_, (c))
int tor_cond_init(tor_cond_t *cond);
void tor_cond_uninit(tor_cond_t *cond);
int tor_cond_wait(tor_cond_t *cond, tor_mutex_t *mutex,
diff --git a/src/common/compress.h b/src/common/compress.h
index 7420f169f..952102bf9 100644
--- a/src/common/compress.h
+++ b/src/common/compress.h
@@ -82,7 +82,7 @@ tor_compress_output_t tor_compress_process(tor_compress_state_t *state,
int finish);
void tor_compress_free_(tor_compress_state_t *state);
#define tor_compress_free(st) \
- FREE_AND_NULL_UNMATCHED(tor_compress_state_t, tor_compress_free_, (st))
+ FREE_AND_NULL(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 986bfe9a6..38a447c1f 100644
--- a/src/common/compress_lzma.h
+++ b/src/common/compress_lzma.h
@@ -33,7 +33,7 @@ tor_lzma_compress_process(tor_lzma_compress_state_t *state,
void tor_lzma_compress_free_(tor_lzma_compress_state_t *state);
#define tor_lzma_compress_free(st) \
- FREE_AND_NULL_UNMATCHED(tor_lzma_compress_state_t, \
+ FREE_AND_NULL(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 701e2f9e8..e3c1a2b33 100644
--- a/src/common/compress_zlib.h
+++ b/src/common/compress_zlib.h
@@ -33,7 +33,7 @@ tor_zlib_compress_process(tor_zlib_compress_state_t *state,
void tor_zlib_compress_free_(tor_zlib_compress_state_t *state);
#define tor_zlib_compress_free(st) \
- FREE_AND_NULL_UNMATCHED(tor_zlib_compress_state_t, \
+ FREE_AND_NULL(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 3e18febb1..9bca24ded 100644
--- a/src/common/compress_zstd.h
+++ b/src/common/compress_zstd.h
@@ -33,7 +33,7 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state,
void tor_zstd_compress_free_(tor_zstd_compress_state_t *state);
#define tor_zstd_compress_free(st) \
- FREE_AND_NULL_UNMATCHED(tor_zstd_compress_state_t, \
+ FREE_AND_NULL(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/container.h b/src/common/container.h
index 95dfa4c90..5d2dce541 100644
--- a/src/common/container.h
+++ b/src/common/container.h
@@ -29,7 +29,7 @@ typedef struct smartlist_t {
MOCK_DECL(smartlist_t *, smartlist_new, (void));
MOCK_DECL(void, smartlist_free_, (smartlist_t *sl));
-#define smartlist_free(sl) FREE_AND_NULL(smartlist, (sl))
+#define smartlist_free(sl) FREE_AND_NULL(smartlist_t, smartlist_free_, (sl))
void smartlist_clear(smartlist_t *sl);
void smartlist_add(smartlist_t *sl, void *element);
@@ -630,7 +630,7 @@ bitarray_free_(bitarray_t *ba)
{
tor_free(ba);
}
-#define bitarray_free(ba) FREE_AND_NULL(bitarray, (ba))
+#define bitarray_free(ba) FREE_AND_NULL(bitarray_t, bitarray_free_, (ba))
/** Set the <b>bit</b>th bit in <b>b</b> to 1. */
static inline void
@@ -694,7 +694,7 @@ digestset_contains(const digestset_t *set, const char *digest)
digestset_t *digestset_new(int max_elements);
void digestset_free_(digestset_t* set);
-#define digestset_free(set) FREE_AND_NULL(digestset, (set))
+#define digestset_free(set) FREE_AND_NULL(digestset_t, digestset_free_, (set))
/* These functions, given an <b>array</b> of <b>n_elements</b>, return the
* <b>nth</b> lowest element. <b>nth</b>=0 gives the lowest element;
diff --git a/src/common/crypto.h b/src/common/crypto.h
index f1061467d..30023bad9 100644
--- a/src/common/crypto.h
+++ b/src/common/crypto.h
@@ -148,7 +148,7 @@ int crypto_global_cleanup(void);
/* environment setup */
MOCK_DECL(crypto_pk_t *,crypto_pk_new,(void));
void crypto_pk_free_(crypto_pk_t *env);
-#define crypto_pk_free(pk) FREE_AND_NULL(crypto_pk, (pk))
+#define crypto_pk_free(pk) FREE_AND_NULL(crypto_pk_t, crypto_pk_free_, (pk))
void crypto_set_tls_dh_prime(void);
crypto_cipher_t *crypto_cipher_new(const char *key);
@@ -158,7 +158,7 @@ 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, (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 +262,7 @@ 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, (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 +281,7 @@ 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, (xof))
+#define crypto_xof_free(xof) FREE_AND_NULL(crypto_xof_t, crypto_xof_free_, (xof))
/* Key negotiation */
#define DH_TYPE_CIRCUIT 1
@@ -297,7 +297,7 @@ 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);
-#define crypto_dh_free(dh) FREE_AND_NULL(crypto_dh, (dh))
+#define crypto_dh_free(dh) FREE_AND_NULL(crypto_dh_t, crypto_dh_free_, (dh))
int crypto_expand_key_material_TAP(const uint8_t *key_in,
size_t key_in_len,
diff --git a/src/common/crypto_ed25519.h b/src/common/crypto_ed25519.h
index 64ccc470e..c05f5dfa9 100644
--- a/src/common/crypto_ed25519.h
+++ b/src/common/crypto_ed25519.h
@@ -119,7 +119,7 @@ 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, (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/log.c b/src/common/log.c
index d305c9ae5..9d4219be1 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_UNMATCHED(logfile_t, log_free_, (lg))
+ FREE_AND_NULL(logfile_t, log_free_, (lg))
/** Helper: map a log severity to descriptive string. */
static inline const char *
diff --git a/src/common/procmon.h b/src/common/procmon.h
index 691a5a124..63777e411 100644
--- a/src/common/procmon.h
+++ b/src/common/procmon.h
@@ -29,7 +29,7 @@ tor_process_monitor_t *tor_process_monitor_new(struct event_base *base,
const char **msg);
void tor_process_monitor_free_(tor_process_monitor_t *procmon);
#define tor_process_monitor_free(procmon) \
- FREE_AND_NULL(tor_process_monitor, (procmon))
+ FREE_AND_NULL(tor_process_monitor_t, tor_process_monitor_free_, (procmon))
#endif /* !defined(TOR_PROCMON_H) */
diff --git a/src/common/storagedir.h b/src/common/storagedir.h
index 8408ab50d..0ddb65542 100644
--- a/src/common/storagedir.h
+++ b/src/common/storagedir.h
@@ -10,7 +10,7 @@ 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, (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/timers.h b/src/common/timers.h
index 86e892016..6d27f3e01 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_UNMATCHED(tor_timer_t, timer_free_, (t))
+#define timer_free(t) FREE_AND_NULL(tor_timer_t, timer_free_, (t))
void timers_initialize(void);
void timers_shutdown(void);
diff --git a/src/common/tortls.h b/src/common/tortls.h
index b293ce20e..df8597db0 100644
--- a/src/common/tortls.h
+++ b/src/common/tortls.h
@@ -217,7 +217,7 @@ void tor_tls_set_renegotiate_callback(tor_tls_t *tls,
void *arg);
int tor_tls_is_server(tor_tls_t *tls);
void tor_tls_free_(tor_tls_t *tls);
-#define tor_tls_free(tls) FREE_AND_NULL(tor_tls, (tls))
+#define tor_tls_free(tls) FREE_AND_NULL(tor_tls_t, tor_tls_free_, (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));
@@ -265,7 +265,7 @@ 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, (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/common/util.h b/src/common/util.h
index 97ad15f83..8dc64ce9f 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -446,7 +446,7 @@ struct process_environment_t {
process_environment_t *process_environment_make(struct smartlist_t *env_vars);
void process_environment_free_(process_environment_t *env);
#define process_environment_free(env) \
- FREE_AND_NULL(process_environment, (env))
+ FREE_AND_NULL(process_environment_t, process_environment_free_, (env))
struct smartlist_t *get_current_process_environment_variables(void);
diff --git a/src/or/channel.h b/src/or/channel.h
index 0ee99dcaf..1ff226d37 100644
--- a/src/or/channel.h
+++ b/src/or/channel.h
@@ -517,9 +517,9 @@ void channel_listener_closed(channel_listener_t *chan_l);
/* Free a channel */
void channel_free_(channel_t *chan);
-#define channel_free(chan) FREE_AND_NULL(channel, (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, (chan_l))
+#define channel_listener_free(chan_l) FREE_AND_NULL(channel_listener_t, channel_listener_free_, (chan_l))
/* State/metadata setters */
@@ -722,7 +722,7 @@ int packed_cell_is_destroy(channel_t *chan,
/* Declare the handle helpers */
HANDLE_DECL(channel, channel_s,)
#define channel_handle_free(h) \
- FREE_AND_NULL(channel_handle, (h))
+ FREE_AND_NULL(channel_handle_t, channel_handle_free_, (h))
#endif /* !defined(TOR_CHANNEL_H) */
diff --git a/src/or/circuitbuild.h b/src/or/circuitbuild.h
index 6c3c91f83..68c6d9ea7 100644
--- a/src/or/circuitbuild.h
+++ b/src/or/circuitbuild.h
@@ -59,7 +59,7 @@ 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, (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/circuitlist.h b/src/or/circuitlist.h
index ffa250b2c..bf3393a94 100644
--- a/src/or/circuitlist.h
+++ b/src/or/circuitlist.h
@@ -82,7 +82,7 @@ smartlist_t *circuit_find_circuits_to_upgrade_from_guard_wait(void);
#ifdef CIRCUITLIST_PRIVATE
STATIC void circuit_free_(circuit_t *circ);
-#define circuit_free(circ) FREE_AND_NULL(circuit, (circ))
+#define circuit_free(circ) FREE_AND_NULL(circuit_t, circuit_free_, (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.h b/src/or/circuitmux.h
index e7f345f67..689decee8 100644
--- a/src/or/circuitmux.h
+++ b/src/or/circuitmux.h
@@ -105,7 +105,7 @@ 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, (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 cc8003fb3..c591a8e54 100644
--- a/src/or/config.h
+++ b/src/or/config.h
@@ -153,7 +153,7 @@ 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, (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 d1811c79b..9ba1606d6 100644
--- a/src/or/connection.h
+++ b/src/or/connection.h
@@ -30,7 +30,7 @@ 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, (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/connection_or.h b/src/or/connection_or.h
index 107af491e..986b8cec4 100644
--- a/src/or/connection_or.h
+++ b/src/or/connection_or.h
@@ -70,7 +70,7 @@ time_t connection_or_client_used(or_connection_t *conn);
MOCK_DECL(int, connection_or_get_num_circuits, (or_connection_t *conn));
void or_handshake_state_free_(or_handshake_state_t *state);
#define or_handshake_state_free(state) \
- FREE_AND_NULL(or_handshake_state, (state))
+ FREE_AND_NULL(or_handshake_state_t, or_handshake_state_free_, (state))
void or_handshake_state_record_cell(or_connection_t *conn,
or_handshake_state_t *state,
const cell_t *cell,
@@ -108,7 +108,7 @@ int var_cell_pack_header(const var_cell_t *cell, char *hdr_out,
var_cell_t *var_cell_new(uint16_t payload_len);
var_cell_t *var_cell_copy(const var_cell_t *src);
void var_cell_free_(var_cell_t *cell);
-#define var_cell_free(cell) FREE_AND_NULL(var_cell, (cell))
+#define var_cell_free(cell) FREE_AND_NULL(var_cell_t, var_cell_free_, (cell))
/* DOCDOC */
#define MIN_LINK_PROTO_FOR_WIDE_CIRC_IDS 4
diff --git a/src/or/conscache.h b/src/or/conscache.h
index 0c02f6ebc..501917bd0 100644
--- a/src/or/conscache.h
+++ b/src/or/conscache.h
@@ -11,11 +11,11 @@ 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, (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, (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 ab44c83b0..f165bdfaf 100644
--- a/src/or/dircollate.h
+++ b/src/or/dircollate.h
@@ -19,7 +19,7 @@ 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, (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 89913038e..08ed5024d 100644
--- a/src/or/directory.h
+++ b/src/or/directory.h
@@ -52,7 +52,7 @@ 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, (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 037294bdb..7c5006b18 100644
--- a/src/or/dirserv.h
+++ b/src/or/dirserv.h
@@ -196,7 +196,7 @@ 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, (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/dirvote.h b/src/or/dirvote.h
index 29fb07273..6a02ea3e3 100644
--- a/src/or/dirvote.h
+++ b/src/or/dirvote.h
@@ -138,7 +138,7 @@ int networkstatus_add_detached_signatures(networkstatus_t *target,
char *networkstatus_get_detached_signatures(smartlist_t *consensuses);
void ns_detached_signatures_free_(ns_detached_signatures_t *s);
#define ns_detached_signatures_free(s) \
- FREE_AND_NULL(ns_detached_signatures, (s))
+ FREE_AND_NULL(ns_detached_signatures_t, ns_detached_signatures_free_, (s))
/* cert manipulation */
authority_cert_t *authority_cert_dup(authority_cert_t *cert);
diff --git a/src/or/entrynodes.h b/src/or/entrynodes.h
index 5fd4c970d..32fcfeadf 100644
--- a/src/or/entrynodes.h
+++ b/src/or/entrynodes.h
@@ -477,7 +477,7 @@ STATIC double get_extreme_restriction_threshold(void);
HANDLE_DECL(entry_guard, entry_guard_t, STATIC)
#define entry_guard_handle_free(h) \
- FREE_AND_NULL(entry_guard_handle, (h))
+ FREE_AND_NULL(entry_guard_handle_t, entry_guard_handle_free_, (h))
STATIC guard_selection_type_t guard_selection_infer_type(
guard_selection_type_t type_in,
@@ -487,7 +487,7 @@ 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, (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,
@@ -573,7 +573,7 @@ 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, (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 bd20acc9a..10b056787 100644
--- a/src/or/hs_common.h
+++ b/src/or/hs_common.h
@@ -182,7 +182,7 @@ 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, (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 5fa180ea5..19158e910 100644
--- a/src/or/hs_descriptor.h
+++ b/src/or/hs_descriptor.h
@@ -209,17 +209,17 @@ 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, (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, (desc))
+ FREE_AND_NULL(hs_desc_plaintext_data_t, hs_desc_plaintext_data_free_, (desc))
void hs_desc_encrypted_data_free_(hs_desc_encrypted_data_t *desc);
#define hs_desc_encrypted_data_free(desc) \
- FREE_AND_NULL(hs_desc_encrypted_data, (desc))
+ FREE_AND_NULL(hs_desc_encrypted_data_t, hs_desc_encrypted_data_free_, (desc))
void hs_desc_link_specifier_free_(hs_desc_link_specifier_t *ls);
#define hs_desc_link_specifier_free(ls) \
- FREE_AND_NULL(hs_desc_link_specifier, (ls))
+ FREE_AND_NULL(hs_desc_link_specifier_t, hs_desc_link_specifier_free_, (ls))
hs_desc_link_specifier_t *hs_desc_link_specifier_new(
const extend_info_t *info, uint8_t type);
@@ -243,7 +243,7 @@ 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, (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 274772ead..b91e5c79b 100644
--- a/src/or/hs_ident.h
+++ b/src/or/hs_ident.h
@@ -120,13 +120,13 @@ 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, (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, (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 +135,7 @@ 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, (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/hs_service.h b/src/or/hs_service.h
index f933ba6ab..bc6987dee 100644
--- a/src/or/hs_service.h
+++ b/src/or/hs_service.h
@@ -250,7 +250,7 @@ void hs_service_free_all(void);
/* Service new/free functions. */
hs_service_t *hs_service_new(const or_options_t *options);
void hs_service_free_(hs_service_t *service);
-#define hs_service_free(s) FREE_AND_NULL(hs_service, (s))
+#define hs_service_free(s) FREE_AND_NULL(hs_service_t, hs_service_free_, (s))
unsigned int hs_service_get_num_services(void);
void hs_service_stage_services(const smartlist_t *service_list);
@@ -296,7 +296,7 @@ STATIC hs_service_intro_point_t *service_intro_point_new(
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_UNMATCHED(hs_service_intro_point_t, \
+ FREE_AND_NULL(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);
@@ -332,7 +332,7 @@ 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_UNMATCHED(hs_service_descriptor_t, \
+ FREE_AND_NULL(hs_service_descriptor_t, \
service_descriptor_free_, (d))
STATIC uint64_t
diff --git a/src/or/networkstatus.h b/src/or/networkstatus.h
index 37350bb1b..93fde8c2c 100644
--- a/src/or/networkstatus.h
+++ b/src/or/networkstatus.h
@@ -19,10 +19,10 @@ 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, (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_UNMATCHED(networkstatus_t, networkstatus_vote_free_, (ns))
+ FREE_AND_NULL(networkstatus_t, networkstatus_vote_free_, (ns))
networkstatus_voter_info_t *networkstatus_get_voter_by_id(
networkstatus_t *vote,
const char *identity);
@@ -128,13 +128,13 @@ 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, (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, (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 559cbb881..48985700e 100644
--- a/src/or/onion.h
+++ b/src/or/onion.h
@@ -32,7 +32,7 @@ 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, (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/onion_fast.h b/src/or/onion_fast.h
index 7d110fd75..c56712e2c 100644
--- a/src/or/onion_fast.h
+++ b/src/or/onion_fast.h
@@ -21,7 +21,7 @@ typedef struct fast_handshake_state_t {
void fast_handshake_state_free_(fast_handshake_state_t *victim);
#define fast_handshake_state_free(st) \
- FREE_AND_NULL(fast_handshake_state, (st))
+ FREE_AND_NULL(fast_handshake_state_t, fast_handshake_state_free_, (st))
int fast_onionskin_create(fast_handshake_state_t **handshake_state_out,
uint8_t *handshake_out);
diff --git a/src/or/onion_ntor.h b/src/or/onion_ntor.h
index 6ca9395dc..f7c962b7d 100644
--- a/src/or/onion_ntor.h
+++ b/src/or/onion_ntor.h
@@ -19,7 +19,7 @@ typedef struct ntor_handshake_state_t ntor_handshake_state_t;
void ntor_handshake_state_free_(ntor_handshake_state_t *state);
#define ntor_handshake_state_free(state) \
- FREE_AND_NULL(ntor_handshake_state, (state))
+ FREE_AND_NULL(ntor_handshake_state_t, ntor_handshake_state_free_, (state))
int onion_skin_ntor_create(const uint8_t *router_id,
const curve25519_public_key_t *router_key,
diff --git a/src/or/policies.h b/src/or/policies.h
index 451a7a7f3..55bf9012b 100644
--- a/src/or/policies.h
+++ b/src/or/policies.h
@@ -117,9 +117,9 @@ int policy_write_item(char *buf, size_t buflen, const addr_policy_t *item,
void addr_policy_list_free_(smartlist_t *p);
#define addr_policy_list_free(lst) \
- FREE_AND_NULL_UNMATCHED(smartlist_t, 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, (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 +127,7 @@ 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, (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 423362cde..492cd13cd 100644
--- a/src/or/proto_socks.h
+++ b/src/or/proto_socks.h
@@ -12,7 +12,7 @@ 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, (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 99e86d76b..3c0530a3a 100644
--- a/src/or/protover.h
+++ b/src/or/protover.h
@@ -84,7 +84,7 @@ 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, (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 9f66aacdd..417942adb 100644
--- a/src/or/relay.h
+++ b/src/or/relay.h
@@ -52,7 +52,7 @@ 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, (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 +96,7 @@ 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, (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 c1e9207a9..30e6a0cc9 100644
--- a/src/or/rendcache.h
+++ b/src/or/rendcache.h
@@ -91,15 +91,15 @@ 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, (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) \
- FREE_AND_NULL_UNMATCHED(rend_cache_failure_intro_t, \
+ FREE_AND_NULL(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_UNMATCHED(rend_cache_failure_t, \
+ FREE_AND_NULL(rend_cache_failure_t, \
rend_cache_failure_entry_free_, (e))
STATIC int cache_failure_intro_lookup(const uint8_t *identity,
const char *service_id,
diff --git a/src/or/rendcommon.h b/src/or/rendcommon.h
index 159754115..3e1edfbcf 100644
--- a/src/or/rendcommon.h
+++ b/src/or/rendcommon.h
@@ -26,14 +26,14 @@ 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, (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, (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, (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 7e9a5d6c5..8d11c7682 100644
--- a/src/or/rendservice.h
+++ b/src/or/rendservice.h
@@ -118,7 +118,7 @@ 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, (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 +190,11 @@ 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, (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, (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 8f9db8c2b..6b845b929 100644
--- a/src/or/replaycache.h
+++ b/src/or/replaycache.h
@@ -34,7 +34,7 @@ struct replaycache_s {
/* replaycache_t free/new */
void replaycache_free_(replaycache_t *r);
-#define replaycache_free(r) FREE_AND_NULL(replaycache, (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/router.h b/src/or/router.h
index e282b9975..696e98366 100644
--- a/src/or/router.h
+++ b/src/or/router.h
@@ -38,7 +38,7 @@ 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_UNMATCHED(di_digest256_map_t, ntor_key_map_free_, (map))
+ FREE_AND_NULL(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.h b/src/or/routerlist.h
index 18f0670ea..ab510dee3 100644
--- a/src/or/routerlist.h
+++ b/src/or/routerlist.h
@@ -97,11 +97,11 @@ 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, (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, (ei))
+#define extrainfo_free(ei) FREE_AND_NULL(extrainfo_t, extrainfo_free_, (ei))
void routerlist_free_(routerlist_t *rl);
-#define routerlist_free(rl) FREE_AND_NULL(routerlist, (rl))
+#define routerlist_free(rl) FREE_AND_NULL(routerlist_t, routerlist_free_, (rl))
void dump_routerlist_mem_usage(int severity);
void routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old,
time_t now);
@@ -195,7 +195,7 @@ 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, (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);
diff --git a/src/or/routerset.h b/src/or/routerset.h
index 57b03fda3..53e8c66c5 100644
--- a/src/or/routerset.h
+++ b/src/or/routerset.h
@@ -41,7 +41,7 @@ void routerset_subtract_nodes(smartlist_t *out,
char *routerset_to_string(const routerset_t *routerset);
int routerset_equal(const routerset_t *old, const routerset_t *new);
void routerset_free_(routerset_t *routerset);
-#define routerset_free(rs) FREE_AND_NULL(routerset, (rs))
+#define routerset_free(rs) FREE_AND_NULL(routerset_t, routerset_free_, (rs))
int routerset_len(const routerset_t *set);
#ifdef ROUTERSET_PRIVATE
diff --git a/src/or/shared_random.h b/src/or/shared_random.h
index 125d50260..675a8d8b0 100644
--- a/src/or/shared_random.h
+++ b/src/or/shared_random.h
@@ -114,7 +114,7 @@ char *sr_get_string_for_vote(void);
char *sr_get_string_for_consensus(const smartlist_t *votes,
int32_t num_srv_agreements);
void sr_commit_free_(sr_commit_t *commit);
-#define sr_commit_free(sr) FREE_AND_NULL(sr_commit, (sr))
+#define sr_commit_free(sr) FREE_AND_NULL(sr_commit_t, sr_commit_free_, (sr))
void sr_srv_encode(char *dst, size_t dst_len, const sr_srv_t *srv);
/* Private methods (only used by shared_random_state.c): */
diff --git a/src/or/statefile.h b/src/or/statefile.h
index d1b9674d4..b4cc4d1dc 100644
--- a/src/or/statefile.h
+++ b/src/or/statefile.h
@@ -21,7 +21,7 @@ void or_state_free_all(void);
#ifdef STATEFILE_PRIVATE
STATIC config_line_t *get_transport_in_state_by_name(const char *transport);
STATIC void or_state_free_(or_state_t *state);
-#define or_state_free(st) FREE_AND_NULL(or_state, (st))
+#define or_state_free(st) FREE_AND_NULL(or_state_t, or_state_free_, (st))
STATIC or_state_t *or_state_new(void);
#endif
diff --git a/src/or/torcert.h b/src/or/torcert.h
index 8e8e6e186..0a8a25204 100644
--- a/src/or/torcert.h
+++ b/src/or/torcert.h
@@ -58,7 +58,7 @@ tor_cert_t *tor_cert_create(const ed25519_keypair_t *signing_key,
tor_cert_t *tor_cert_parse(const uint8_t *cert, size_t certlen);
void tor_cert_free_(tor_cert_t *cert);
-#define tor_cert_free(cert) FREE_AND_NULL(tor_cert, (cert))
+#define tor_cert_free(cert) FREE_AND_NULL(tor_cert_t, tor_cert_free_, (cert))
int tor_cert_get_checkable_sig(ed25519_checkable_t *checkable_out,
const tor_cert_t *out,
@@ -86,7 +86,7 @@ rsa_ed25519_crosscert_check, (const uint8_t *crosscert,
or_handshake_certs_t *or_handshake_certs_new(void);
void or_handshake_certs_free_(or_handshake_certs_t *certs);
#define or_handshake_certs_free(certs) \
- FREE_AND_NULL(or_handshake_certs, (certs))
+ FREE_AND_NULL(or_handshake_certs_t, or_handshake_certs_free_, (certs))
int or_handshake_certs_rsa_ok(int severity,
or_handshake_certs_t *certs,
tor_tls_t *tls,
diff --git a/src/or/transports.h b/src/or/transports.h
index 9f348f58e..1b2786472 100644
--- a/src/or/transports.h
+++ b/src/or/transports.h
@@ -36,7 +36,7 @@ MOCK_DECL(int, transport_add_from_config,
(const tor_addr_t *addr, uint16_t port,
const char *name, int socks_ver));
void transport_free_(transport_t *transport);
-#define transport_free(tr) FREE_AND_NULL(transport, (tr))
+#define transport_free(tr) FREE_AND_NULL(transport_t, transport_free_, (tr))
transport_t *transport_get_by_name(const char *name);
diff --git a/src/test/test_handles.c b/src/test/test_handles.c
index 03ae0883c..eb1e1f1bb 100644
--- a/src/test/test_handles.c
+++ b/src/test/test_handles.c
@@ -14,7 +14,7 @@ typedef struct demo_t {
HANDLE_DECL(demo, demo_t, static)
#define demo_handle_free(h) \
- FREE_AND_NULL(demo_handle, (h))
+ FREE_AND_NULL(demo_handle_t, demo_handle_free_, (h))
HANDLE_IMPL(demo, demo_t, static)
static demo_t *
1
0
08 Dec '17
commit 5508ee29d56c948efc7a07747e37cc27538e17a8
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Tue Nov 21 09:57:05 2017 -0500
changes file for big free macro-ization branch
---
changes/bug24337 | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/changes/bug24337 b/changes/bug24337
new file mode 100644
index 000000000..82b430425
--- /dev/null
+++ b/changes/bug24337
@@ -0,0 +1,8 @@
+ o Minor features (defensive programming):
+ - Most of the functions in Tor that free objects have been replaced
+ with macros that free the objects and set the corresponding pointers
+ to NULL. This change should help prevent a large class of dangling
+ pointer bugs. Closes ticket 24337.
+
+ - Where possible, the tor_free() macro now only evaluates its input once.
+ Part of ticket 24337.
1
0
08 Dec '17
commit 0792cc107ef588b9f9fa27165b73e19fbf07e92b
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Tue Nov 21 08:39:07 2017 -0500
Convert connection_free to a nulling macro.
---
src/or/circuitlist.c | 2 +-
src/or/connection.c | 4 ++--
src/or/connection.h | 3 ++-
src/or/connection_edge.c | 12 ++++++------
src/or/connection_or.c | 4 ++--
src/or/dns.c | 10 +++++-----
src/or/dnsserv.c | 4 ++--
src/test/test_dns.c | 6 +++---
8 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index 0171ed4f1..34a61a34e 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -1087,7 +1087,7 @@ circuit_free_all(void)
while (or_circ->resolving_streams) {
edge_connection_t *next_conn;
next_conn = or_circ->resolving_streams->next_stream;
- connection_free(TO_CONN(or_circ->resolving_streams));
+ connection_free_(TO_CONN(or_circ->resolving_streams));
or_circ->resolving_streams = next_conn;
}
}
diff --git a/src/or/connection.c b/src/or/connection.c
index 8f2ddaa0e..3c37c59b4 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2001 Matej Pfajfar.
+ /* Copyright (c) 2001 Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2017, The Tor Project, Inc. */
@@ -675,7 +675,7 @@ connection_free_minimal(connection_t *conn)
/** Make sure <b>conn</b> isn't in any of the global conn lists; then free it.
*/
MOCK_IMPL(void,
-connection_free,(connection_t *conn))
+connection_free_,(connection_t *conn))
{
if (!conn)
return;
diff --git a/src/or/connection.h b/src/or/connection.h
index 89f80a42c..d1811c79b 100644
--- a/src/or/connection.h
+++ b/src/or/connection.h
@@ -29,7 +29,8 @@ connection_t *connection_new(int type, int socket_family);
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));
+MOCK_DECL(void,connection_free_,(connection_t *conn));
+#define connection_free(conn) FREE_AND_NULL(connection, (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/connection_edge.c b/src/or/connection_edge.c
index 41f0fe6a1..d7937818d 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -3327,7 +3327,7 @@ handle_hs_exit_conn(circuit_t *circ, edge_connection_t *conn)
relay_send_end_cell_from_edge(conn->stream_id, circ,
END_STREAM_REASON_DONE,
origin_circ->cpath->prev);
- connection_free(TO_CONN(conn));
+ connection_free_(TO_CONN(conn));
/* Drop the circuit here since it might be someone deliberately
* scanning the hidden service ports. Note that this mitigates port
@@ -3524,7 +3524,7 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
if (we_are_hibernating()) {
relay_send_end_cell_from_edge(rh.stream_id, circ,
END_STREAM_REASON_HIBERNATING, NULL);
- connection_free(TO_CONN(n_stream));
+ connection_free_(TO_CONN(n_stream));
return 0;
}
@@ -3602,7 +3602,7 @@ connection_exit_begin_resolve(cell_t *cell, or_circuit_t *circ)
return 0;
case 1: /* The result was cached; a resolved cell was sent. */
if (!dummy_conn->base_.marked_for_close)
- connection_free(TO_CONN(dummy_conn));
+ connection_free_(TO_CONN(dummy_conn));
return 0;
case 0: /* resolve added to pending list */
assert_circuit_ok(TO_CIRCUIT(circ));
@@ -3775,8 +3775,8 @@ connection_exit_connect_dir(edge_connection_t *exitconn)
if (connection_add(TO_CONN(exitconn))<0) {
connection_edge_end(exitconn, END_STREAM_REASON_RESOURCELIMIT);
- connection_free(TO_CONN(exitconn));
- connection_free(TO_CONN(dirconn));
+ connection_free_(TO_CONN(exitconn));
+ connection_free_(TO_CONN(dirconn));
return 0;
}
@@ -3788,7 +3788,7 @@ connection_exit_connect_dir(edge_connection_t *exitconn)
connection_edge_end(exitconn, END_STREAM_REASON_RESOURCELIMIT);
connection_close_immediate(TO_CONN(exitconn));
connection_mark_for_close(TO_CONN(exitconn));
- connection_free(TO_CONN(dirconn));
+ connection_free_(TO_CONN(dirconn));
return 0;
}
diff --git a/src/or/connection_or.c b/src/or/connection_or.c
index 7af1f2b64..fa8991596 100644
--- a/src/or/connection_or.c
+++ b/src/or/connection_or.c
@@ -1247,7 +1247,7 @@ connection_or_connect, (const tor_addr_t *_addr, uint16_t port,
fmt_addrport(&TO_CONN(conn)->addr, TO_CONN(conn)->port));
}
- connection_free(TO_CONN(conn));
+ connection_free_(TO_CONN(conn));
return NULL;
}
@@ -1260,7 +1260,7 @@ connection_or_connect, (const tor_addr_t *_addr, uint16_t port,
connection_or_connect_failed(conn,
errno_to_orconn_end_reason(socket_error),
tor_socket_strerror(socket_error));
- connection_free(TO_CONN(conn));
+ connection_free_(TO_CONN(conn));
return NULL;
case 0:
connection_watch_events(TO_CONN(conn), READ_EVENT | WRITE_EVENT);
diff --git a/src/or/dns.c b/src/or/dns.c
index f140051e8..1f00fe5b4 100644
--- a/src/or/dns.c
+++ b/src/or/dns.c
@@ -457,7 +457,7 @@ purge_expired_resolves(time_t now)
if (!pendconn->base_.marked_for_close) {
connection_edge_end(pendconn, END_STREAM_REASON_TIMEOUT);
circuit_detach_stream(circuit_get_by_edge_conn(pendconn), pendconn);
- connection_free(TO_CONN(pendconn));
+ connection_free_(TO_CONN(pendconn));
}
tor_free(pend);
}
@@ -670,7 +670,7 @@ dns_resolve(edge_connection_t *exitconn)
/* If we made the connection pending, then we freed it already in
* dns_cancel_pending_resolve(). If we marked it for close, it'll
* get freed from the main loop. Otherwise, can free it now. */
- connection_free(TO_CONN(exitconn));
+ connection_free_(TO_CONN(exitconn));
}
break;
default:
@@ -1101,7 +1101,7 @@ dns_cancel_pending_resolve,(const char *address))
if (circ)
circuit_detach_stream(circ, pendconn);
if (!pendconn->base_.marked_for_close)
- connection_free(TO_CONN(pendconn));
+ connection_free_(TO_CONN(pendconn));
resolve->pending_connections = pend->next;
tor_free(pend);
}
@@ -1230,7 +1230,7 @@ inform_pending_connections(cached_resolve_t *resolve)
/* This detach must happen after we send the resolved cell. */
circuit_detach_stream(circuit_get_by_edge_conn(pendconn), pendconn);
}
- connection_free(TO_CONN(pendconn));
+ connection_free_(TO_CONN(pendconn));
} else {
circuit_t *circ;
if (pendconn->base_.purpose == EXIT_PURPOSE_CONNECT) {
@@ -1259,7 +1259,7 @@ inform_pending_connections(cached_resolve_t *resolve)
circ = circuit_get_by_edge_conn(pendconn);
tor_assert(circ);
circuit_detach_stream(circ, pendconn);
- connection_free(TO_CONN(pendconn));
+ connection_free_(TO_CONN(pendconn));
}
}
resolve->pending_connections = pend->next;
diff --git a/src/or/dnsserv.c b/src/or/dnsserv.c
index d254717a5..9385561d9 100644
--- a/src/or/dnsserv.c
+++ b/src/or/dnsserv.c
@@ -172,7 +172,7 @@ evdns_server_callback(struct evdns_server_request *req, void *data_)
if (connection_add(ENTRY_TO_CONN(entry_conn)) < 0) {
log_warn(LD_APP, "Couldn't register dummy connection for DNS request");
evdns_server_request_respond(req, DNS_ERR_SERVERFAILED);
- connection_free(ENTRY_TO_CONN(entry_conn));
+ connection_free_(ENTRY_TO_CONN(entry_conn));
return;
}
@@ -249,7 +249,7 @@ dnsserv_launch_request(const char *name, int reverse,
if (connection_add(TO_CONN(conn))<0) {
log_warn(LD_APP, "Couldn't register dummy connection for RESOLVE request");
- connection_free(TO_CONN(conn));
+ connection_free_(TO_CONN(conn));
return -1;
}
diff --git a/src/test/test_dns.c b/src/test/test_dns.c
index 66b231b6d..1fee01d2c 100644
--- a/src/test/test_dns.c
+++ b/src/test/test_dns.c
@@ -124,7 +124,7 @@ static int n_connection_free = 0;
static connection_t *last_freed_conn = NULL;
static void
-NS(connection_free)(connection_t *conn)
+NS(connection_free_)(connection_t *conn)
{
n_connection_free++;
@@ -267,7 +267,7 @@ NS(test_main)(void *arg)
*/
NS_MOCK(dns_cancel_pending_resolve);
- NS_MOCK(connection_free);
+ NS_MOCK(connection_free_);
exitconn->on_circuit = &(on_circuit->base_);
exitconn->base_.purpose = EXIT_PURPOSE_RESOLVE;
@@ -294,7 +294,7 @@ NS(test_main)(void *arg)
NS_UNMOCK(send_resolved_cell);
NS_UNMOCK(send_resolved_hostname_cell);
NS_UNMOCK(dns_cancel_pending_resolve);
- NS_UNMOCK(connection_free);
+ NS_UNMOCK(connection_free_);
tor_free(on_circuit);
tor_free(exitconn);
tor_free(nextconn);
1
0
08 Dec '17
commit a48ba072a98a5d946079e2e0c15c84bb8c9d1a19
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Tue Nov 21 08:36:08 2017 -0500
Rename connection_free_ to connection_free_minimal.
---
src/or/connection.c | 11 ++---
src/or/connection.h | 2 +-
src/test/test_dir_handle_get.c | 96 +++++++++++++++++++++---------------------
src/test/test_entryconn.c | 34 +++++++--------
src/test/test_extorport.c | 10 ++---
src/test/test_hs_cache.c | 2 +-
src/test/test_hs_client.c | 8 ++--
src/test/test_link_handshake.c | 14 +++---
src/test/test_oom.c | 2 +-
src/test/test_routerlist.c | 2 +-
10 files changed, 91 insertions(+), 90 deletions(-)
diff --git a/src/or/connection.c b/src/or/connection.c
index 92ccd3d5c..8f2ddaa0e 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -499,7 +499,7 @@ conn_listener_type_supports_af_unix(int type)
* if <b>conn</b> is an OR or OP connection.
*/
STATIC void
-connection_free_(connection_t *conn)
+connection_free_minimal(connection_t *conn)
{
void *mem;
size_t memlen;
@@ -704,7 +704,7 @@ connection_free,(connection_t *conn))
}
#endif /* 1 */
connection_unregister_events(conn);
- connection_free_(conn);
+ connection_free_minimal(conn);
}
/**
@@ -5239,8 +5239,8 @@ proxy_type_to_string(int proxy_type)
return NULL; /*Unreached*/
}
-/** Call connection_free_() on every connection in our array, and release all
- * storage held by connection.c.
+/** Call connection_free_minimal() on every connection in our array, and
+ * release all storage held by connection.c.
*
* Don't do the checks in connection_free(), because they will
* fail.
@@ -5264,7 +5264,8 @@ connection_free_all(void)
/* Clear out our list of broken connections */
clear_broken_connection_map(0);
- SMARTLIST_FOREACH(conns, connection_t *, conn, connection_free_(conn));
+ SMARTLIST_FOREACH(conns, connection_t *, conn,
+ connection_free_minimal(conn));
if (outgoing_addrs) {
SMARTLIST_FOREACH(outgoing_addrs, tor_addr_t *, addr, tor_free(addr));
diff --git a/src/or/connection.h b/src/or/connection.h
index 1d41a3c4f..89f80a42c 100644
--- a/src/or/connection.h
+++ b/src/or/connection.h
@@ -267,7 +267,7 @@ connection_is_moribund(connection_t *conn)
void connection_check_oos(int n_socks, int failed);
#ifdef CONNECTION_PRIVATE
-STATIC void connection_free_(connection_t *conn);
+STATIC void connection_free_minimal(connection_t *conn);
/* Used only by connection.c and test*.c */
uint32_t bucket_millis_empty(int tokens_before, uint32_t last_empty_time,
diff --git a/src/test/test_dir_handle_get.c b/src/test/test_dir_handle_get.c
index fe26657ad..414690c95 100644
--- a/src/test/test_dir_handle_get.c
+++ b/src/test/test_dir_handle_get.c
@@ -88,7 +88,7 @@ test_dir_handle_get_bad_request(void *data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -117,7 +117,7 @@ test_dir_handle_get_v1_command_not_found(void *data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -164,7 +164,7 @@ test_dir_handle_get_v1_command(void *data)
done:
UNMOCK(connection_write_to_buf_impl_);
UNMOCK(get_dirportfrontpage);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
tor_free(body);
}
@@ -190,7 +190,7 @@ test_dir_handle_get_not_found(void *data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -225,7 +225,7 @@ test_dir_handle_get_robots_txt(void *data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
tor_free(body);
}
@@ -254,7 +254,7 @@ test_dir_handle_get_rendezvous2_not_found_if_not_encrypted(void *data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -282,7 +282,7 @@ test_dir_handle_get_rendezvous2_on_encrypted_conn_with_invalid_desc_id(
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -315,7 +315,7 @@ test_dir_handle_get_rendezvous2_on_encrypted_conn_not_well_formed(void *data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -344,7 +344,7 @@ test_dir_handle_get_rendezvous2_not_found(void *data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
rend_cache_free_all();
}
@@ -424,7 +424,7 @@ test_dir_handle_get_rendezvous2_on_encrypted_conn_success(void *data)
UNMOCK(connection_write_to_buf_impl_);
NS_UNMOCK(router_get_my_routerinfo);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
tor_free(body);
rend_encoded_v2_service_descriptor_free(desc_holder);
@@ -457,7 +457,7 @@ test_dir_handle_get_micro_d_not_found(void *data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -541,7 +541,7 @@ test_dir_handle_get_micro_d(void *data)
UNMOCK(connection_write_to_buf_impl_);
or_options_free(mock_options); mock_options = NULL;
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
tor_free(body);
smartlist_free(list);
@@ -595,7 +595,7 @@ test_dir_handle_get_micro_d_server_busy(void *data)
UNMOCK(connection_write_to_buf_impl_);
or_options_free(mock_options); mock_options = NULL;
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
smartlist_free(list);
microdesc_free_all();
@@ -632,7 +632,7 @@ test_dir_handle_get_networkstatus_bridges_not_found_without_auth(void *data)
UNMOCK(get_options);
UNMOCK(connection_write_to_buf_impl_);
or_options_free(mock_options); mock_options = NULL;
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -672,7 +672,7 @@ test_dir_handle_get_networkstatus_bridges(void *data)
UNMOCK(get_options);
UNMOCK(connection_write_to_buf_impl_);
or_options_free(mock_options); mock_options = NULL;
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -709,7 +709,7 @@ test_dir_handle_get_networkstatus_bridges_not_found_wrong_auth(void *data)
UNMOCK(get_options);
UNMOCK(connection_write_to_buf_impl_);
or_options_free(mock_options); mock_options = NULL;
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -737,7 +737,7 @@ test_dir_handle_get_server_descriptors_not_found(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
or_options_free(mock_options); mock_options = NULL;
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -798,7 +798,7 @@ test_dir_handle_get_server_descriptors_all(void* data)
done:
NS_UNMOCK(router_get_my_routerinfo);
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
tor_free(body);
@@ -902,7 +902,7 @@ test_dir_handle_get_server_descriptors_authority(void* data)
UNMOCK(connection_write_to_buf_impl_);
tor_free(mock_routerinfo->cache_info.signed_descriptor_body);
tor_free(mock_routerinfo);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
tor_free(body);
crypto_pk_free(identity_pkey);
@@ -974,7 +974,7 @@ test_dir_handle_get_server_descriptors_fp(void* data)
UNMOCK(connection_write_to_buf_impl_);
tor_free(mock_routerinfo->cache_info.signed_descriptor_body);
tor_free(mock_routerinfo);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
tor_free(body);
crypto_pk_free(identity_pkey);
@@ -1038,7 +1038,7 @@ test_dir_handle_get_server_descriptors_d(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
tor_free(mock_routerinfo);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
tor_free(body);
crypto_pk_free(identity_pkey);
@@ -1094,7 +1094,7 @@ test_dir_handle_get_server_descriptors_busy(void* data)
UNMOCK(get_options);
UNMOCK(connection_write_to_buf_impl_);
tor_free(mock_routerinfo);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
crypto_pk_free(identity_pkey);
@@ -1125,7 +1125,7 @@ test_dir_handle_get_server_keys_bad_req(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -1151,7 +1151,7 @@ test_dir_handle_get_server_keys_all_not_found(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -1210,7 +1210,7 @@ test_dir_handle_get_server_keys_all(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
tor_free(body);
@@ -1240,7 +1240,7 @@ test_dir_handle_get_server_keys_authority_not_found(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -1288,7 +1288,7 @@ test_dir_handle_get_server_keys_authority(void* data)
done:
UNMOCK(get_my_v3_authority_cert);
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
tor_free(body);
authority_cert_free(mock_cert); mock_cert = NULL;
@@ -1316,7 +1316,7 @@ test_dir_handle_get_server_keys_fp_not_found(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -1370,7 +1370,7 @@ test_dir_handle_get_server_keys_fp(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
tor_free(body);
clear_dir_servers();
@@ -1399,7 +1399,7 @@ test_dir_handle_get_server_keys_sk_not_found(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -1444,7 +1444,7 @@ test_dir_handle_get_server_keys_sk(void* data)
done:
UNMOCK(get_my_v3_authority_cert);
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
authority_cert_free(mock_cert); mock_cert = NULL;
tor_free(header);
tor_free(body);
@@ -1472,7 +1472,7 @@ test_dir_handle_get_server_keys_fpsk_not_found(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -1529,7 +1529,7 @@ test_dir_handle_get_server_keys_fpsk(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
tor_free(body);
@@ -1583,7 +1583,7 @@ test_dir_handle_get_server_keys_busy(void* data)
done:
UNMOCK(get_options);
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
or_options_free(mock_options); mock_options = NULL;
@@ -1649,7 +1649,7 @@ test_dir_handle_get_status_vote_current_consensus_ns_not_enough_sigs(void* d)
UNMOCK(connection_write_to_buf_impl_);
UNMOCK(get_options);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
tor_free(stats);
smartlist_free(mock_ns_val->voters);
@@ -1690,7 +1690,7 @@ test_dir_handle_get_status_vote_current_consensus_ns_not_found(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
UNMOCK(get_options);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
tor_free(stats);
or_options_free(mock_options); mock_options = NULL;
@@ -1764,7 +1764,7 @@ test_dir_handle_get_status_vote_current_consensus_too_old(void *data)
UNMOCK(networkstatus_get_latest_consensus_by_flavor);
UNMOCK(connection_write_to_buf_impl_);
UNMOCK(get_options);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
tor_free(mock_ns_val);
or_options_free(mock_options); mock_options = NULL;
@@ -1825,7 +1825,7 @@ status_vote_current_consensus_ns_test(char **header, char **body,
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
}
static void
@@ -1948,7 +1948,7 @@ test_dir_handle_get_status_vote_current_not_found(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -1971,7 +1971,7 @@ status_vote_current_d_test(char **header, char **body, size_t *body_l)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
}
static void
@@ -1991,7 +1991,7 @@ status_vote_next_d_test(char **header, char **body, size_t *body_l)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
}
static void
@@ -2116,7 +2116,7 @@ test_dir_handle_get_status_vote_next_not_found(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -2135,7 +2135,7 @@ status_vote_next_consensus_test(char **header, char **body, size_t *body_used)
body, body_used, 18, 0);
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
}
static void
@@ -2175,7 +2175,7 @@ test_dir_handle_get_status_vote_current_authority_not_found(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -2199,7 +2199,7 @@ test_dir_handle_get_status_vote_next_authority_not_found(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
}
@@ -2281,7 +2281,7 @@ status_vote_next_consensus_signatures_test(char **header, char **body,
body, body_used, 22, 0);
done:
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
UNMOCK(connection_write_to_buf_impl_);
}
@@ -2429,7 +2429,7 @@ test_dir_handle_get_status_vote_next_authority(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
UNMOCK(get_my_v3_authority_cert);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
tor_free(body);
authority_cert_free(mock_cert); mock_cert = NULL;
@@ -2511,7 +2511,7 @@ test_dir_handle_get_status_vote_current_authority(void* data)
done:
UNMOCK(connection_write_to_buf_impl_);
UNMOCK(get_my_v3_authority_cert);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
tor_free(header);
tor_free(body);
authority_cert_free(mock_cert); mock_cert = NULL;
diff --git a/src/test/test_entryconn.c b/src/test/test_entryconn.c
index c29b1a712..9d8a072c7 100644
--- a/src/test/test_entryconn.c
+++ b/src/test/test_entryconn.c
@@ -34,7 +34,7 @@ entryconn_rewrite_teardown(const struct testcase_t *tc, void *arg)
(void)tc;
entry_connection_t *ec = arg;
if (ec)
- connection_free_(ENTRY_TO_CONN(ec));
+ connection_free_minimal(ENTRY_TO_CONN(ec));
addressmap_free_all();
return 1;
}
@@ -156,8 +156,8 @@ test_entryconn_rewrite_automap_ipv4(void *arg)
ec->socks_request->address);
done:
- connection_free_(ENTRY_TO_CONN(ec2));
- connection_free_(ENTRY_TO_CONN(ec3));
+ connection_free_minimal(ENTRY_TO_CONN(ec2));
+ connection_free_minimal(ENTRY_TO_CONN(ec3));
}
/* Automap on resolve, connect to automapped address, resolve again and get
@@ -230,9 +230,9 @@ test_entryconn_rewrite_automap_ipv6(void *arg)
ec->socks_request->address);
done:
- connection_free_(ENTRY_TO_CONN(ec));
- connection_free_(ENTRY_TO_CONN(ec2));
- connection_free_(ENTRY_TO_CONN(ec3));
+ connection_free_minimal(ENTRY_TO_CONN(ec));
+ connection_free_minimal(ENTRY_TO_CONN(ec2));
+ connection_free_minimal(ENTRY_TO_CONN(ec3));
}
#if 0
@@ -283,7 +283,7 @@ test_entryconn_rewrite_automap_reverse(void *arg)
tt_int_op(rr.exit_source, OP_EQ, ADDRMAPSRC_NONE);
done:
- connection_free_(ENTRY_TO_CONN(ec2));
+ connection_free_minimal(ENTRY_TO_CONN(ec2));
}
#endif /* 0 */
@@ -333,7 +333,7 @@ test_entryconn_rewrite_cached_dns_ipv4(void *arg)
tt_str_op(ec2->socks_request->address, OP_EQ, "240.240.241.241");
done:
- connection_free_(ENTRY_TO_CONN(ec2));
+ connection_free_minimal(ENTRY_TO_CONN(ec2));
}
/* Rewrite because of cached DNS entry. */
@@ -385,8 +385,8 @@ test_entryconn_rewrite_cached_dns_ipv6(void *arg)
tt_str_op(ec2->socks_request->address, OP_EQ, "[::f00f]");
done:
- connection_free_(ENTRY_TO_CONN(ec));
- connection_free_(ENTRY_TO_CONN(ec2));
+ connection_free_minimal(ENTRY_TO_CONN(ec));
+ connection_free_minimal(ENTRY_TO_CONN(ec2));
}
/* Fail to connect to unmapped address in virtual range. */
@@ -426,7 +426,7 @@ test_entryconn_rewrite_unmapped_virtual(void *arg)
tt_int_op(rr.exit_source, OP_EQ, ADDRMAPSRC_NONE);
done:
- connection_free_(ENTRY_TO_CONN(ec2));
+ connection_free_minimal(ENTRY_TO_CONN(ec2));
}
/* Rewrite because of mapaddress option */
@@ -507,7 +507,7 @@ test_entryconn_rewrite_automap_exit(void *arg)
tt_int_op(rr.end_reason, OP_EQ, END_STREAM_REASON_TORPROTOCOL);
done:
- connection_free_(ENTRY_TO_CONN(ec2));
+ connection_free_minimal(ENTRY_TO_CONN(ec2));
}
/* Rewrite into .exit because of mapaddress */
@@ -618,9 +618,9 @@ test_entryconn_rewrite_mapaddress_automap_onion(void *arg)
*/
done:
- connection_free_(ENTRY_TO_CONN(ec2));
- connection_free_(ENTRY_TO_CONN(ec3));
- connection_free_(ENTRY_TO_CONN(ec4));
+ connection_free_minimal(ENTRY_TO_CONN(ec2));
+ connection_free_minimal(ENTRY_TO_CONN(ec3));
+ connection_free_minimal(ENTRY_TO_CONN(ec4));
}
static void
@@ -678,8 +678,8 @@ test_entryconn_rewrite_mapaddress_automap_onion_common(entry_connection_t *ec,
"abcdefghijklmnop.onion"));
done:
- connection_free_(ENTRY_TO_CONN(ec2));
- connection_free_(ENTRY_TO_CONN(ec3));
+ connection_free_minimal(ENTRY_TO_CONN(ec2));
+ connection_free_minimal(ENTRY_TO_CONN(ec3));
}
/* This time is the same, but we start with a mapping from a non-onion
diff --git a/src/test/test_extorport.c b/src/test/test_extorport.c
index e18deb270..cadef257f 100644
--- a/src/test/test_extorport.c
+++ b/src/test/test_extorport.c
@@ -58,11 +58,11 @@ test_ext_or_id_map(void *arg)
done:
if (c1)
- connection_free_(TO_CONN(c1));
+ connection_free_minimal(TO_CONN(c1));
if (c2)
- connection_free_(TO_CONN(c2));
+ connection_free_minimal(TO_CONN(c2));
if (c3)
- connection_free_(TO_CONN(c3));
+ connection_free_minimal(TO_CONN(c3));
tor_free(idp);
tor_free(idp2);
connection_or_clear_ext_or_id_map();
@@ -145,7 +145,7 @@ test_ext_or_write_command(void *arg)
done:
if (c1)
- connection_free_(TO_CONN(c1));
+ connection_free_minimal(TO_CONN(c1));
tor_free(cp);
tor_free(buf);
UNMOCK(connection_write_to_buf_impl_);
@@ -591,7 +591,7 @@ test_ext_or_handshake(void *arg)
UNMOCK(connection_write_to_buf_impl_);
UNMOCK(crypto_rand);
if (conn)
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
#undef CONTAINS
#undef WRITE
}
diff --git a/src/test/test_hs_cache.c b/src/test/test_hs_cache.c
index 91b13be86..458ce1a92 100644
--- a/src/test/test_hs_cache.c
+++ b/src/test/test_hs_cache.c
@@ -259,7 +259,7 @@ helper_fetch_desc_from_hsdir(const ed25519_public_key_t *blinded_key)
done:
tor_free(hsdir_query_str);
if (conn)
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
return received_desc;
}
diff --git a/src/test/test_hs_client.c b/src/test/test_hs_client.c
index 6e2d956b4..7ee7210bc 100644
--- a/src/test/test_hs_client.c
+++ b/src/test/test_hs_client.c
@@ -227,7 +227,7 @@ test_e2e_rend_circuit_setup_legacy(void *arg)
tt_ptr_op(TO_EDGE_CONN(conn)->on_circuit, OP_EQ, TO_CIRCUIT(or_circ));
done:
- connection_free_(conn);
+ connection_free_minimal(conn);
if (or_circ)
tor_free(TO_CIRCUIT(or_circ)->n_chan);
circuit_free_(TO_CIRCUIT(or_circ));
@@ -297,7 +297,7 @@ test_e2e_rend_circuit_setup(void *arg)
tt_ptr_op(TO_EDGE_CONN(conn)->on_circuit, OP_EQ, TO_CIRCUIT(or_circ));
done:
- connection_free_(conn);
+ connection_free_minimal(conn);
if (or_circ)
tor_free(TO_CIRCUIT(or_circ)->n_chan);
circuit_free_(TO_CIRCUIT(or_circ));
@@ -560,7 +560,7 @@ test_descriptor_fetch(void *arg)
smartlist_add(get_connection_array(), TO_CONN(dir_conn));
ret = hs_client_refetch_hsdesc(&service_pk);
smartlist_remove(get_connection_array(), TO_CONN(dir_conn));
- connection_free_(TO_CONN(dir_conn));
+ connection_free_minimal(TO_CONN(dir_conn));
tt_int_op(ret, OP_EQ, HS_CLIENT_FETCH_PENDING);
}
@@ -579,7 +579,7 @@ test_descriptor_fetch(void *arg)
tt_int_op(ec->edge_.end_reason, OP_EQ, END_STREAM_REASON_RESOLVEFAILED);
done:
- connection_free_(ENTRY_TO_CONN(ec));
+ connection_free_minimal(ENTRY_TO_CONN(ec));
UNMOCK(networkstatus_get_live_consensus);
UNMOCK(router_have_minimum_dir_info);
hs_free_all();
diff --git a/src/test/test_link_handshake.c b/src/test/test_link_handshake.c
index 422d41907..6840072d7 100644
--- a/src/test/test_link_handshake.c
+++ b/src/test/test_link_handshake.c
@@ -302,8 +302,8 @@ test_link_handshake_certs_ok(void *arg)
mock_own_cert = mock_peer_cert = NULL;
memset(c1->identity_digest, 0, sizeof(c1->identity_digest));
memset(c2->identity_digest, 0, sizeof(c2->identity_digest));
- connection_free_(TO_CONN(c1));
- connection_free_(TO_CONN(c2));
+ connection_free_minimal(TO_CONN(c1));
+ connection_free_minimal(TO_CONN(c2));
tor_free(cell1);
tor_free(cell2);
certs_cell_free(cc1);
@@ -343,7 +343,7 @@ recv_certs_cleanup(const struct testcase_t *test, void *obj)
tor_free(d->cell);
certs_cell_free(d->ccell);
connection_or_clear_identity(d->c);
- connection_free_(TO_CONN(d->c));
+ connection_free_minimal(TO_CONN(d->c));
circuitmux_free(d->chan->base_.cmux);
tor_free(d->chan);
crypto_pk_free(d->key1);
@@ -930,7 +930,7 @@ test_link_handshake_send_authchallenge(void *arg)
done:
UNMOCK(connection_or_write_var_cell_to_buf);
- connection_free_(TO_CONN(c1));
+ connection_free_minimal(TO_CONN(c1));
tor_free(cell1);
tor_free(cell2);
crypto_pk_free(rsa0);
@@ -955,7 +955,7 @@ recv_authchallenge_cleanup(const struct testcase_t *test, void *obj)
if (d) {
tor_free(d->cell);
- connection_free_(TO_CONN(d->c));
+ connection_free_minimal(TO_CONN(d->c));
circuitmux_free(d->chan->base_.cmux);
tor_free(d->chan);
tor_free(d);
@@ -1158,8 +1158,8 @@ authenticate_data_cleanup(const struct testcase_t *test, void *arg)
tor_free(d->cell);
connection_or_clear_identity(d->c1);
connection_or_clear_identity(d->c2);
- connection_free_(TO_CONN(d->c1));
- connection_free_(TO_CONN(d->c2));
+ connection_free_minimal(TO_CONN(d->c1));
+ connection_free_minimal(TO_CONN(d->c2));
circuitmux_free(d->chan2->base_.cmux);
tor_free(d->chan2);
crypto_pk_free(d->key1);
diff --git a/src/test/test_oom.c b/src/test/test_oom.c
index cf28690a2..bd1d62e88 100644
--- a/src/test/test_oom.c
+++ b/src/test/test_oom.c
@@ -335,7 +335,7 @@ test_oom_streambuf(void *arg)
circuit_free(c5);
SMARTLIST_FOREACH(edgeconns, edge_connection_t *, ec,
- connection_free_(TO_CONN(ec)));
+ connection_free_minimal(TO_CONN(ec)));
smartlist_free(edgeconns);
UNMOCK(circuit_mark_for_close_);
diff --git a/src/test/test_routerlist.c b/src/test/test_routerlist.c
index fd29e8f17..c19d66ef9 100644
--- a/src/test/test_routerlist.c
+++ b/src/test/test_routerlist.c
@@ -520,7 +520,7 @@ test_directory_guard_fetch_with_no_dirinfo(void *arg)
done:
tor_free(consensus_text_md);
tor_free(dummy_state);
- connection_free_(TO_CONN(conn));
+ connection_free_minimal(TO_CONN(conn));
entry_guards_free_all();
teardown_capture_of_logs();
}
1
0
[tor/master] Make all the free() functions from container.h clear their targets
by nickm@torproject.org 08 Dec '17
by nickm@torproject.org 08 Dec '17
08 Dec '17
commit 94db8f32e46925c3a64def751e5d2efbddbdf417
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Nov 17 11:46:25 2017 -0500
Make all the free() functions from container.h clear their targets
---
src/common/container.c | 6 +++---
src/common/container.h | 27 +++++++++++++++++++++------
src/or/config.c | 4 +++-
src/or/router.c | 1 +
src/or/routerlist.c | 4 ++++
src/test/test_dir.c | 4 ++--
src/test/test_routerset.c | 46 +++++++++++++++++++++++-----------------------
7 files changed, 57 insertions(+), 35 deletions(-)
diff --git a/src/common/container.c b/src/common/container.c
index 8645cb482..a6e3c11f3 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -42,7 +42,7 @@ smartlist_new,(void))
* list's elements.
*/
MOCK_IMPL(void,
-smartlist_free,(smartlist_t *sl))
+smartlist_free_,(smartlist_t *sl))
{
if (!sl)
return;
@@ -1335,7 +1335,7 @@ digest256map_assign_key(digest256map_entry_t *ent, const uint8_t *key)
* those entries. If free_val is provided, invoked it every value in \
* <b>map</b>. */ \
MOCK_IMPL(void, \
- prefix##_free, (maptype *map, void (*free_val)(void*))) \
+ prefix##_free_, (maptype *map, void (*free_val)(void*))) \
{ \
prefix##_entry_t **ent, **next, *this; \
if (!map) \
@@ -1525,7 +1525,7 @@ digestset_new(int max_elements)
/** Free all storage held in <b>set</b>. */
void
-digestset_free(digestset_t *set)
+digestset_free_(digestset_t *set)
{
if (!set)
return;
diff --git a/src/common/container.h b/src/common/container.h
index f6affd3bc..95dfa4c90 100644
--- a/src/common/container.h
+++ b/src/common/container.h
@@ -28,7 +28,9 @@ typedef struct smartlist_t {
} smartlist_t;
MOCK_DECL(smartlist_t *, smartlist_new, (void));
-MOCK_DECL(void, smartlist_free, (smartlist_t *sl));
+MOCK_DECL(void, smartlist_free_, (smartlist_t *sl));
+#define smartlist_free(sl) FREE_AND_NULL(smartlist, (sl))
+
void smartlist_clear(smartlist_t *sl);
void smartlist_add(smartlist_t *sl, void *element);
void smartlist_add_all(smartlist_t *sl, const smartlist_t *s2);
@@ -350,7 +352,7 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join,
void* prefix##set(maptype *map, keytype key, void *val); \
void* prefix##get(const maptype *map, keytype key); \
void* prefix##remove(maptype *map, keytype key); \
- MOCK_DECL(void, prefix##free, (maptype *map, void (*free_val)(void*))); \
+ MOCK_DECL(void, prefix##free_, (maptype *map, void (*free_val)(void*))); \
int prefix##isempty(const maptype *map); \
int prefix##size(const maptype *map); \
prefix##iter_t *prefix##iter_init(maptype *map); \
@@ -368,6 +370,16 @@ DECLARE_MAP_FNS(digestmap_t, const char *, digestmap_);
* table. */
DECLARE_MAP_FNS(digest256map_t, const uint8_t *, digest256map_);
+#define MAP_FREE_AND_NULL(maptype, map, fn) \
+ do { \
+ maptype ## _free_((map), (fn)); \
+ (map) = NULL; \
+ } while (0)
+
+#define strmap_free(map, fn) MAP_FREE_AND_NULL(strmap, (map), (fn))
+#define digestmap_free(map, fn) MAP_FREE_AND_NULL(digestmap, (map), (fn))
+#define digest256map_free(map, fn) MAP_FREE_AND_NULL(digest256map, (map), (fn))
+
#undef DECLARE_MAP_FNS
/** Iterates over the key-value pairs in a map <b>map</b> in order.
@@ -528,9 +540,9 @@ void* strmap_remove_lc(strmap_t *map, const char *key);
return (valtype*)digestmap_remove((digestmap_t*)map, key); \
} \
ATTR_UNUSED static inline void \
- prefix##f##ree(maptype *map, void (*free_val)(void*)) \
+ prefix##f##ree_(maptype *map, void (*free_val)(void*)) \
{ \
- digestmap_free((digestmap_t*)map, free_val); \
+ digestmap_free_((digestmap_t*)map, free_val); \
} \
ATTR_UNUSED static inline int \
prefix##isempty(maptype *map) \
@@ -614,10 +626,12 @@ bitarray_expand(bitarray_t *ba,
}
/** Free the bit array <b>ba</b>. */
static inline void
-bitarray_free(bitarray_t *ba)
+bitarray_free_(bitarray_t *ba)
{
tor_free(ba);
}
+#define bitarray_free(ba) FREE_AND_NULL(bitarray, (ba))
+
/** Set the <b>bit</b>th bit in <b>b</b> to 1. */
static inline void
bitarray_set(bitarray_t *b, int bit)
@@ -679,7 +693,8 @@ digestset_contains(const digestset_t *set, const char *digest)
#undef BIT
digestset_t *digestset_new(int max_elements);
-void digestset_free(digestset_t* set);
+void digestset_free_(digestset_t* set);
+#define digestset_free(set) FREE_AND_NULL(digestset, (set))
/* These functions, given an <b>array</b> of <b>n_elements</b>, return the
* <b>nth</b> lowest element. <b>nth</b>=0 gives the lowest element;
diff --git a/src/or/config.c b/src/or/config.c
index b0a140d23..fac3a36d1 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -778,7 +778,7 @@ static or_options_t *global_default_options = NULL;
/** Name of most recently read torrc file. */
static char *torrc_fname = NULL;
/** Name of the most recently read torrc-defaults file.*/
-static char *torrc_defaults_fname;
+static char *torrc_defaults_fname = NULL;
/** Configuration options set by command line. */
static config_line_t *global_cmdline_options = NULL;
/** Non-configuration options set by the command line */
@@ -977,6 +977,8 @@ config_free_all(void)
tor_free(the_short_tor_version);
tor_free(the_tor_version);
+
+ have_parsed_cmdline = 0;
}
/** Make <b>address</b> -- a piece of information related to our operation as
diff --git a/src/or/router.c b/src/or/router.c
index 8ad5d038e..614d76a36 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -3698,6 +3698,7 @@ router_free_all(void)
crypto_pk_free(lastonionkey);
crypto_pk_free(server_identitykey);
crypto_pk_free(client_identitykey);
+
tor_mutex_free(key_lock);
routerinfo_free(desc_routerinfo);
extrainfo_free(desc_extrainfo);
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index fb8225e0d..50d5cc1ab 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -143,6 +143,10 @@ DECLARE_TYPED_DIGESTMAP_FNS(dsmap_, digest_ds_map_t, download_status_t)
#define DSMAP_FOREACH(map, keyvar, valvar) \
DIGESTMAP_FOREACH(dsmap_to_digestmap(map), keyvar, download_status_t *, \
valvar)
+#define eimap_free(map, fn) MAP_FREE_AND_NULL(eimap, (map), (fn))
+#define rimap_free(map, fn) MAP_FREE_AND_NULL(rimap, (map), (fn))
+#define dsmap_free(map, fn) MAP_FREE_AND_NULL(dsmap, (map), (fn))
+#define sdmap_free(map, fn) MAP_FREE_AND_NULL(sdmap, (map), (fn))
/* Forward declaration for cert_list_t */
typedef struct cert_list_t cert_list_t;
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index ee4a9780b..4cab307ce 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -664,7 +664,7 @@ test_dir_extrainfo_parsing(void *arg)
escaped(NULL);
extrainfo_free(ei);
routerinfo_free(ri);
- digestmap_free((digestmap_t*)map, routerinfo_free_wrapper_);
+ digestmap_free_((digestmap_t*)map, routerinfo_free_wrapper_);
}
static void
@@ -760,7 +760,7 @@ test_dir_parse_router_list(void *arg)
smartlist_free(chunks);
routerinfo_free(ri);
if (map) {
- digestmap_free((digestmap_t*)map, routerinfo_free_wrapper_);
+ digestmap_free_((digestmap_t*)map, routerinfo_free_wrapper_);
router_get_routerlist()->identity_map =
(struct digest_ri_map_t*)digestmap_new();
}
diff --git a/src/test/test_routerset.c b/src/test/test_routerset.c
index 6da2275c3..8eb19c3c2 100644
--- a/src/test/test_routerset.c
+++ b/src/test/test_routerset.c
@@ -2084,28 +2084,28 @@ NS(test_main)(void *arg)
* Structural test for routerset_free, where the routerset is NULL.
*/
-NS_DECL(void, smartlist_free, (smartlist_t *sl));
+NS_DECL(void, smartlist_free_, (smartlist_t *sl));
static void
NS(test_main)(void *arg)
{
(void)arg;
- NS_MOCK(smartlist_free);
+ NS_MOCK(smartlist_free_);
routerset_free(NULL);
- tt_int_op(CALLED(smartlist_free), OP_EQ, 0);
+ tt_int_op(CALLED(smartlist_free_), OP_EQ, 0);
done:
;
}
void
-NS(smartlist_free)(smartlist_t *s)
+NS(smartlist_free_)(smartlist_t *s)
{
(void)s;
- CALLED(smartlist_free)++;
+ CALLED(smartlist_free_)++;
}
#undef NS_SUBMODULE
@@ -2115,9 +2115,9 @@ NS(smartlist_free)(smartlist_t *s)
* Structural test for routerset_free.
*/
-NS_DECL(void, smartlist_free, (smartlist_t *sl));
-NS_DECL(void, strmap_free,(strmap_t *map, void (*free_val)(void*)));
-NS_DECL(void, digestmap_free, (digestmap_t *map, void (*free_val)(void*)));
+NS_DECL(void, smartlist_free_, (smartlist_t *sl));
+NS_DECL(void, strmap_free_,(strmap_t *map, void (*free_val)(void*)));
+NS_DECL(void, digestmap_free_, (digestmap_t *map, void (*free_val)(void*)));
static void
NS(test_main)(void *arg)
@@ -2125,39 +2125,39 @@ NS(test_main)(void *arg)
routerset_t *routerset = routerset_new();
(void)arg;
- NS_MOCK(smartlist_free);
- NS_MOCK(strmap_free);
- NS_MOCK(digestmap_free);
+ NS_MOCK(smartlist_free_);
+ NS_MOCK(strmap_free_);
+ NS_MOCK(digestmap_free_);
routerset_free(routerset);
- tt_int_op(CALLED(smartlist_free), OP_NE, 0);
- tt_int_op(CALLED(strmap_free), OP_NE, 0);
- tt_int_op(CALLED(digestmap_free), OP_NE, 0);
+ tt_int_op(CALLED(smartlist_free_), OP_NE, 0);
+ tt_int_op(CALLED(strmap_free_), OP_NE, 0);
+ tt_int_op(CALLED(digestmap_free_), OP_NE, 0);
done:
;
}
void
-NS(smartlist_free)(smartlist_t *s)
+NS(smartlist_free_)(smartlist_t *s)
{
- CALLED(smartlist_free)++;
- smartlist_free__real(s);
+ CALLED(smartlist_free_)++;
+ smartlist_free___real(s);
}
void
-NS(strmap_free)(strmap_t *map, void (*free_val)(void*))
+NS(strmap_free_)(strmap_t *map, void (*free_val)(void*))
{
- CALLED(strmap_free)++;
- strmap_free__real(map, free_val);
+ CALLED(strmap_free_)++;
+ strmap_free___real(map, free_val);
}
void
-NS(digestmap_free)(digestmap_t *map, void (*free_val)(void*))
+NS(digestmap_free_)(digestmap_t *map, void (*free_val)(void*))
{
- CALLED(digestmap_free)++;
- digestmap_free__real(map, free_val);
+ CALLED(digestmap_free_)++;
+ digestmap_free___real(map, free_val);
}
#undef NS_SUBMODULE
1
0
[tor/master] Convert the rest of src/common's headers to use FREE_AND_NULL
by nickm@torproject.org 08 Dec '17
by nickm@torproject.org 08 Dec '17
08 Dec '17
commit c92ac9f5cbb4440b5f87c7e0dd6bec5147d72405
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Fri Nov 17 12:27:25 2017 -0500
Convert the rest of src/common's headers to use FREE_AND_NULL
---
src/common/address.c | 6 +++---
src/common/address.h | 13 +++++--------
src/common/aes.c | 4 ++--
src/common/aes.h | 3 ++-
src/common/buffers.c | 2 +-
src/common/buffers.h | 3 ++-
src/common/compat_libevent.c | 4 ++--
src/common/compat_libevent.h | 6 ++++--
src/common/compat_threads.c | 4 ++--
src/common/compat_threads.h | 6 ++++--
src/common/compress.c | 2 +-
src/common/compress.h | 3 ++-
src/common/compress_lzma.c | 2 +-
src/common/compress_lzma.h | 3 ++-
src/common/compress_zlib.c | 2 +-
src/common/compress_zlib.h | 3 ++-
src/common/compress_zstd.c | 2 +-
src/common/compress_zstd.h | 3 ++-
src/common/confline.c | 2 +-
src/common/confline.h | 7 ++++++-
src/common/di_ops.c | 2 +-
src/common/di_ops.h | 7 ++++++-
src/common/handles.h | 4 ++--
src/common/log.c | 6 ++++--
src/common/memarea.c | 2 +-
src/common/memarea.h | 7 ++++++-
src/common/procmon.c | 2 +-
src/common/procmon.h | 4 +++-
src/common/storagedir.c | 2 +-
src/common/storagedir.h | 4 +++-
src/common/timers.c | 2 +-
src/common/timers.h | 3 ++-
src/common/util.c | 2 +-
src/common/util.h | 4 +++-
src/or/channel.h | 2 ++
src/or/conscache.h | 2 ++
src/or/entrynodes.h | 3 +++
src/or/policies.c | 4 ++--
src/test/test-timers.c | 2 +-
src/test/test_address.c | 16 ++++++++--------
src/test/test_handles.c | 2 ++
src/test/test_policy.c | 8 ++++----
42 files changed, 105 insertions(+), 65 deletions(-)
diff --git a/src/common/address.c b/src/common/address.c
index dbe129be5..0c0ba782a 100644
--- a/src/common/address.c
+++ b/src/common/address.c
@@ -1759,14 +1759,14 @@ get_interface_address6,(int severity, sa_family_t family, tor_addr_t *addr))
break;
} SMARTLIST_FOREACH_END(a);
- free_interface_address6_list(addrs);
+ interface_address6_list_free(addrs);
return rv;
}
/** Free a smartlist of IP addresses returned by get_interface_address6_list.
*/
void
-free_interface_address6_list(smartlist_t *addrs)
+interface_address6_list_free_(smartlist_t *addrs)
{
if (addrs != NULL) {
SMARTLIST_FOREACH(addrs, tor_addr_t *, a, tor_free(a));
@@ -1781,7 +1781,7 @@ free_interface_address6_list(smartlist_t *addrs)
* An empty smartlist means that there are no addresses of the selected type
* matching these criteria.
* Returns NULL on failure.
- * Use free_interface_address6_list to free the returned list.
+ * Use interface_address6_list_free to free the returned list.
*/
MOCK_IMPL(smartlist_t *,
get_interface_address6_list,(int severity,
diff --git a/src/common/address.h b/src/common/address.h
index c7f693575..84d136d67 100644
--- a/src/common/address.h
+++ b/src/common/address.h
@@ -206,7 +206,9 @@ const char * fmt_addr32(uint32_t addr);
MOCK_DECL(int,get_interface_address6,(int severity, sa_family_t family,
tor_addr_t *addr));
-void free_interface_address6_list(smartlist_t * addrs);
+void interface_address6_list_free_(smartlist_t * addrs);// XXXX
+#define interface_address6_list_free(addrs) \
+ FREE_AND_NULL(interface_address6_list, (addrs))
MOCK_DECL(smartlist_t *,get_interface_address6_list,(int severity,
sa_family_t family,
int include_internal));
@@ -321,13 +323,8 @@ int addr_mask_get_bits(uint32_t mask);
int tor_inet_ntoa(const struct in_addr *in, char *buf, size_t buf_len);
char *tor_dup_ip(uint32_t addr) ATTR_MALLOC;
MOCK_DECL(int,get_interface_address,(int severity, uint32_t *addr));
-/** Free a smartlist of IP addresses returned by get_interface_address_list.
- */
-static inline void
-free_interface_address_list(smartlist_t *addrs)
-{
- free_interface_address6_list(addrs);
-}
+#define interface_address_list_free(lst)\
+ interface_address6_list_free(lst)
/** Return a smartlist of the IPv4 addresses of all interfaces on the server.
* Excludes loopback and multicast addresses. Only includes internal addresses
* if include_internal is true. (Note that a relay behind NAT may use an
diff --git a/src/common/aes.c b/src/common/aes.c
index df4368fdb..9b5b0197e 100644
--- a/src/common/aes.c
+++ b/src/common/aes.c
@@ -110,7 +110,7 @@ aes_new_cipher(const uint8_t *key, const uint8_t *iv, int key_bits)
return (aes_cnt_cipher_t *) cipher;
}
void
-aes_cipher_free(aes_cnt_cipher_t *cipher_)
+aes_cipher_free_(aes_cnt_cipher_t *cipher_)
{
if (!cipher_)
return;
@@ -324,7 +324,7 @@ aes_set_key(aes_cnt_cipher_t *cipher, const uint8_t *key, int key_bits)
/** Release storage held by <b>cipher</b>
*/
void
-aes_cipher_free(aes_cnt_cipher_t *cipher)
+aes_cipher_free_(aes_cnt_cipher_t *cipher)
{
if (!cipher)
return;
diff --git a/src/common/aes.h b/src/common/aes.h
index 1e400a56e..4874f728d 100644
--- a/src/common/aes.h
+++ b/src/common/aes.h
@@ -17,7 +17,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);
+void aes_cipher_free_(aes_cnt_cipher_t *cipher);
+#define aes_cipher_free(cipher) FREE_AND_NULL(aes_cipher, (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/buffers.c b/src/common/buffers.c
index a21cf2ab5..fad575ccc 100644
--- a/src/common/buffers.c
+++ b/src/common/buffers.c
@@ -409,7 +409,7 @@ buf_slack(const buf_t *buf)
/** Release storage held by <b>buf</b>. */
void
-buf_free(buf_t *buf)
+buf_free_(buf_t *buf)
{
if (!buf)
return;
diff --git a/src/common/buffers.h b/src/common/buffers.h
index dd96ddcb6..34e9711b2 100644
--- a/src/common/buffers.h
+++ b/src/common/buffers.h
@@ -24,7 +24,8 @@ struct tor_compress_state_t;
buf_t *buf_new(void);
buf_t *buf_new_with_capacity(size_t size);
size_t buf_get_default_chunk_size(const buf_t *buf);
-void buf_free(buf_t *buf);
+void buf_free_(buf_t *buf);
+#define buf_free(b) FREE_AND_NULL(buf, (b))
void buf_clear(buf_t *buf);
buf_t *buf_copy(const buf_t *buf);
diff --git a/src/common/compat_libevent.c b/src/common/compat_libevent.c
index 1c3a1b9f3..10489bf29 100644
--- a/src/common/compat_libevent.c
+++ b/src/common/compat_libevent.c
@@ -69,7 +69,7 @@ suppress_libevent_log_msg(const char *msg)
/* Wrapper for event_free() that tolerates tor_event_free(NULL) */
void
-tor_event_free(struct event *ev)
+tor_event_free_(struct event *ev)
{
if (ev == NULL)
return;
@@ -213,7 +213,7 @@ periodic_timer_new(struct event_base *base,
/** Stop and free a periodic timer */
void
-periodic_timer_free(periodic_timer_t *timer)
+periodic_timer_free_(periodic_timer_t *timer)
{
if (!timer)
return;
diff --git a/src/common/compat_libevent.h b/src/common/compat_libevent.h
index 3d8672fc6..65807315c 100644
--- a/src/common/compat_libevent.h
+++ b/src/common/compat_libevent.h
@@ -19,7 +19,8 @@ void suppress_libevent_log_msg(const char *msg);
evdns_add_server_port_with_base(tor_libevent_get_base(), \
(sock),(tcp),(cb),(data));
-void tor_event_free(struct event *ev);
+void tor_event_free_(struct event *ev);
+#define tor_event_free(ev) FREE_AND_NULL(tor_event, (ev))
typedef struct periodic_timer_t periodic_timer_t;
@@ -27,7 +28,8 @@ periodic_timer_t *periodic_timer_new(struct event_base *base,
const struct timeval *tv,
void (*cb)(periodic_timer_t *timer, void *data),
void *data);
-void periodic_timer_free(periodic_timer_t *);
+void periodic_timer_free_(periodic_timer_t *);
+#define periodic_timer_free(t) FREE_AND_NULL(periodic_timer, (t))
#define tor_event_base_loopexit event_base_loopexit
#define tor_event_base_loopbreak event_base_loopbreak
diff --git a/src/common/compat_threads.c b/src/common/compat_threads.c
index 208d3138d..09aafedb2 100644
--- a/src/common/compat_threads.c
+++ b/src/common/compat_threads.c
@@ -48,7 +48,7 @@ tor_mutex_new_nonrecursive(void)
}
/** Release all storage and system resources held by <b>m</b>. */
void
-tor_mutex_free(tor_mutex_t *m)
+tor_mutex_free_(tor_mutex_t *m)
{
if (!m)
return;
@@ -68,7 +68,7 @@ tor_cond_new(void)
/** Free all storage held in <b>c</b>. */
void
-tor_cond_free(tor_cond_t *c)
+tor_cond_free_(tor_cond_t *c)
{
if (!c)
return;
diff --git a/src/common/compat_threads.h b/src/common/compat_threads.h
index 42f14eab2..26e291ae6 100644
--- a/src/common/compat_threads.h
+++ b/src/common/compat_threads.h
@@ -50,7 +50,8 @@ void tor_mutex_init(tor_mutex_t *m);
void tor_mutex_init_nonrecursive(tor_mutex_t *m);
void tor_mutex_acquire(tor_mutex_t *m);
void tor_mutex_release(tor_mutex_t *m);
-void tor_mutex_free(tor_mutex_t *m);
+void tor_mutex_free_(tor_mutex_t *m);
+#define tor_mutex_free(m) FREE_AND_NULL(tor_mutex, (m))
void tor_mutex_uninit(tor_mutex_t *m);
unsigned long tor_get_thread_id(void);
void tor_threads_init(void);
@@ -77,7 +78,8 @@ typedef struct tor_cond_t {
} tor_cond_t;
tor_cond_t *tor_cond_new(void);
-void tor_cond_free(tor_cond_t *cond);
+void tor_cond_free_(tor_cond_t *cond);
+#define tor_cond_free(c) FREE_AND_NULL(tor_cond, (c))
int tor_cond_init(tor_cond_t *cond);
void tor_cond_uninit(tor_cond_t *cond);
int tor_cond_wait(tor_cond_t *cond, tor_mutex_t *mutex,
diff --git a/src/common/compress.c b/src/common/compress.c
index bc12a58ad..47c93cf6a 100644
--- a/src/common/compress.c
+++ b/src/common/compress.c
@@ -598,7 +598,7 @@ tor_compress_process(tor_compress_state_t *state,
/** Deallocate <b>state</b>. */
void
-tor_compress_free(tor_compress_state_t *state)
+tor_compress_free_(tor_compress_state_t *state)
{
if (state == NULL)
return;
diff --git a/src/common/compress.h b/src/common/compress.h
index 23a981747..eee4a315d 100644
--- a/src/common/compress.h
+++ b/src/common/compress.h
@@ -80,7 +80,8 @@ tor_compress_output_t tor_compress_process(tor_compress_state_t *state,
char **out, size_t *out_len,
const char **in, size_t *in_len,
int finish);
-void tor_compress_free(tor_compress_state_t *state);
+void tor_compress_free_(tor_compress_state_t *state);
+#define tor_compress_free(st) FREE_AND_NULL(tor_compress, (st))
size_t tor_compress_state_size(const tor_compress_state_t *state);
diff --git a/src/common/compress_lzma.c b/src/common/compress_lzma.c
index 6426ede4f..051c59ba2 100644
--- a/src/common/compress_lzma.c
+++ b/src/common/compress_lzma.c
@@ -323,7 +323,7 @@ tor_lzma_compress_process(tor_lzma_compress_state_t *state,
/** Deallocate <b>state</b>. */
void
-tor_lzma_compress_free(tor_lzma_compress_state_t *state)
+tor_lzma_compress_free_(tor_lzma_compress_state_t *state)
{
if (state == NULL)
return;
diff --git a/src/common/compress_lzma.h b/src/common/compress_lzma.h
index 7639d98a7..1e92fd660 100644
--- a/src/common/compress_lzma.h
+++ b/src/common/compress_lzma.h
@@ -31,7 +31,8 @@ tor_lzma_compress_process(tor_lzma_compress_state_t *state,
const char **in, size_t *in_len,
int finish);
-void tor_lzma_compress_free(tor_lzma_compress_state_t *state);
+void tor_lzma_compress_free_(tor_lzma_compress_state_t *state);
+#define tor_lzma_compress_free(st) FREE_AND_NULL(tor_lzma_compress, (st))
size_t tor_lzma_compress_state_size(const tor_lzma_compress_state_t *state);
diff --git a/src/common/compress_zlib.c b/src/common/compress_zlib.c
index 284542e88..23d71d27b 100644
--- a/src/common/compress_zlib.c
+++ b/src/common/compress_zlib.c
@@ -265,7 +265,7 @@ tor_zlib_compress_process(tor_zlib_compress_state_t *state,
/** Deallocate <b>state</b>. */
void
-tor_zlib_compress_free(tor_zlib_compress_state_t *state)
+tor_zlib_compress_free_(tor_zlib_compress_state_t *state)
{
if (state == NULL)
return;
diff --git a/src/common/compress_zlib.h b/src/common/compress_zlib.h
index 8ace467bf..3377e0e8d 100644
--- a/src/common/compress_zlib.h
+++ b/src/common/compress_zlib.h
@@ -31,7 +31,8 @@ tor_zlib_compress_process(tor_zlib_compress_state_t *state,
const char **in, size_t *in_len,
int finish);
-void tor_zlib_compress_free(tor_zlib_compress_state_t *state);
+void tor_zlib_compress_free_(tor_zlib_compress_state_t *state);
+#define tor_zlib_compress_free(st) FREE_AND_NULL(tor_zlib_compress, (st))
size_t tor_zlib_compress_state_size(const tor_zlib_compress_state_t *state);
diff --git a/src/common/compress_zstd.c b/src/common/compress_zstd.c
index c1cdaf17a..0db87d61b 100644
--- a/src/common/compress_zstd.c
+++ b/src/common/compress_zstd.c
@@ -399,7 +399,7 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state,
/** Deallocate <b>state</b>. */
void
-tor_zstd_compress_free(tor_zstd_compress_state_t *state)
+tor_zstd_compress_free_(tor_zstd_compress_state_t *state)
{
if (state == NULL)
return;
diff --git a/src/common/compress_zstd.h b/src/common/compress_zstd.h
index 02466010f..9f67a9c58 100644
--- a/src/common/compress_zstd.h
+++ b/src/common/compress_zstd.h
@@ -31,7 +31,8 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state,
const char **in, size_t *in_len,
int finish);
-void tor_zstd_compress_free(tor_zstd_compress_state_t *state);
+void tor_zstd_compress_free_(tor_zstd_compress_state_t *state);
+#define tor_zstd_compress_free(st) FREE_AND_NULL(tor_zstd_compress, (st))
size_t tor_zstd_compress_state_size(const tor_zstd_compress_state_t *state);
diff --git a/src/common/confline.c b/src/common/confline.c
index 781ad2a12..bf613ab74 100644
--- a/src/common/confline.c
+++ b/src/common/confline.c
@@ -330,7 +330,7 @@ config_process_include(const char *path, int recursion_level, int extended,
* Free all the configuration lines on the linked list <b>front</b>.
*/
void
-config_free_lines(config_line_t *front)
+config_free_lines_(config_line_t *front)
{
config_line_t *tmp;
diff --git a/src/common/confline.h b/src/common/confline.h
index feeb9f249..772a9bbbd 100644
--- a/src/common/confline.h
+++ b/src/common/confline.h
@@ -48,7 +48,12 @@ int config_get_lines(const char *string, config_line_t **result, int extended);
int config_get_lines_include(const char *string, config_line_t **result,
int extended, int *has_include,
smartlist_t *opened_lst);
-void config_free_lines(config_line_t *front);
+void config_free_lines_(config_line_t *front);
+#define config_free_lines(front) \
+ do { \
+ config_free_lines_(front); \
+ (front) = NULL; \
+ } while (0)
const char *parse_config_line_from_str_verbose(const char *line,
char **key_out, char **value_out,
const char **err_out);
diff --git a/src/common/di_ops.c b/src/common/di_ops.c
index 7c0b4e763..90e9357c8 100644
--- a/src/common/di_ops.c
+++ b/src/common/di_ops.c
@@ -148,7 +148,7 @@ struct di_digest256_map_t {
/** Release all storage held in <b>map</b>, calling free_fn on each value
* as we go. */
void
-dimap_free(di_digest256_map_t *map, dimap_free_fn free_fn)
+dimap_free_(di_digest256_map_t *map, dimap_free_fn free_fn)
{
while (map) {
di_digest256_map_t *victim = map;
diff --git a/src/common/di_ops.h b/src/common/di_ops.h
index e79973ba5..67d9c9f0d 100644
--- a/src/common/di_ops.h
+++ b/src/common/di_ops.h
@@ -37,7 +37,12 @@ int safe_mem_is_zero(const void *mem, size_t sz);
typedef struct di_digest256_map_t di_digest256_map_t;
typedef void (*dimap_free_fn)(void *);
-void dimap_free(di_digest256_map_t *map, dimap_free_fn free_fn);
+void dimap_free_(di_digest256_map_t *map, dimap_free_fn free_fn);
+#define dimap_free(map, free_fn) \
+ do { \
+ dimap_free_((map), (free_fn)); \
+ (map) = NULL; \
+ } while (0)
void dimap_add_entry(di_digest256_map_t **map,
const uint8_t *key, void *val);
void *dimap_search(const di_digest256_map_t *map, const uint8_t *key,
diff --git a/src/common/handles.h b/src/common/handles.h
index a610753a1..aef8cd89e 100644
--- a/src/common/handles.h
+++ b/src/common/handles.h
@@ -59,7 +59,7 @@
#define HANDLE_DECL(name, structname, linkage) \
typedef struct name ## _handle_t name ## _handle_t; \
linkage name ## _handle_t *name ## _handle_new(struct structname *object); \
- linkage void name ## _handle_free(name ## _handle_t *); \
+ linkage void name ## _handle_free_(name ## _handle_t *); \
linkage struct structname *name ## _handle_get(name ## _handle_t *); \
linkage void name ## _handles_clear(struct structname *object);
@@ -113,7 +113,7 @@
} \
\
linkage void \
- name ## _handle_free(struct name ## _handle_t *ref) \
+ name ## _handle_free_(struct name ## _handle_t *ref) \
{ \
if (! ref) return; \
name ## _handle_head_t *head = ref->head; \
diff --git a/src/common/log.c b/src/common/log.c
index 0becb5ce0..83098b101 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -63,7 +63,9 @@ typedef struct logfile_t {
* log for each log domain? */
} logfile_t;
-static void log_free(logfile_t *victim);
+static void log_free_(logfile_t *victim);
+#define log_free(lg) \
+ FREE_AND_NULL(log, (lg))
/** Helper: map a log severity to descriptive string. */
static inline const char *
@@ -721,7 +723,7 @@ log_fn_ratelim_(ratelim_t *ratelim, int severity, log_domain_mask_t domain,
/** Free all storage held by <b>victim</b>. */
static void
-log_free(logfile_t *victim)
+log_free_(logfile_t *victim)
{
if (!victim)
return;
diff --git a/src/common/memarea.c b/src/common/memarea.c
index b059987e0..fa7b69a43 100644
--- a/src/common/memarea.c
+++ b/src/common/memarea.c
@@ -153,7 +153,7 @@ memarea_new(void)
/** Free <b>area</b>, invalidating all pointers returned from memarea_alloc()
* and friends for this area */
void
-memarea_drop_all(memarea_t *area)
+memarea_drop_all_(memarea_t *area)
{
memarea_chunk_t *chunk, *next;
for (chunk = area->first; chunk; chunk = next) {
diff --git a/src/common/memarea.h b/src/common/memarea.h
index c3d954e1c..5207e8a5b 100644
--- a/src/common/memarea.h
+++ b/src/common/memarea.h
@@ -8,7 +8,12 @@
typedef struct memarea_t memarea_t;
memarea_t *memarea_new(void);
-void memarea_drop_all(memarea_t *area);
+void memarea_drop_all_(memarea_t *area);
+#define memarea_drop_all(area) \
+ do { \
+ memarea_drop_all_(area); \
+ (area) = NULL; \
+ } while (0)
void memarea_clear(memarea_t *area);
int memarea_owns_ptr(const memarea_t *area, const void *ptr);
void *memarea_alloc(memarea_t *area, size_t sz);
diff --git a/src/common/procmon.c b/src/common/procmon.c
index 26c11823e..abcbbeaa2 100644
--- a/src/common/procmon.c
+++ b/src/common/procmon.c
@@ -325,7 +325,7 @@ tor_process_monitor_poll_cb(evutil_socket_t unused1, short unused2,
/** Free the process-termination monitor <b>procmon</b>. */
void
-tor_process_monitor_free(tor_process_monitor_t *procmon)
+tor_process_monitor_free_(tor_process_monitor_t *procmon)
{
if (procmon == NULL)
return;
diff --git a/src/common/procmon.h b/src/common/procmon.h
index 10ead11ba..691a5a124 100644
--- a/src/common/procmon.h
+++ b/src/common/procmon.h
@@ -27,7 +27,9 @@ tor_process_monitor_t *tor_process_monitor_new(struct event_base *base,
tor_procmon_callback_t cb,
void *cb_arg,
const char **msg);
-void tor_process_monitor_free(tor_process_monitor_t *procmon);
+void tor_process_monitor_free_(tor_process_monitor_t *procmon);
+#define tor_process_monitor_free(procmon) \
+ FREE_AND_NULL(tor_process_monitor, (procmon))
#endif /* !defined(TOR_PROCMON_H) */
diff --git a/src/common/storagedir.c b/src/common/storagedir.c
index 31933f64c..cd0c78706 100644
--- a/src/common/storagedir.c
+++ b/src/common/storagedir.c
@@ -59,7 +59,7 @@ storage_dir_new(const char *dirname, int max_files)
* Drop all in-RAM storage for <b>d</b>. Does not delete any files.
*/
void
-storage_dir_free(storage_dir_t *d)
+storage_dir_free_(storage_dir_t *d)
{
if (d == NULL)
return;
diff --git a/src/common/storagedir.h b/src/common/storagedir.h
index 3de0afc36..8408ab50d 100644
--- a/src/common/storagedir.h
+++ b/src/common/storagedir.h
@@ -9,7 +9,9 @@ struct config_line_t;
struct sandbox_cfg_elem;
storage_dir_t * storage_dir_new(const char *dirname, int n_files);
-void storage_dir_free(storage_dir_t *d);
+void storage_dir_free_(storage_dir_t *d);
+#define storage_dir_free(d) FREE_AND_NULL(storage_dir, (d))
+
int storage_dir_register_with_sandbox(storage_dir_t *d,
struct sandbox_cfg_elem **cfg);
const smartlist_t *storage_dir_list(storage_dir_t *d);
diff --git a/src/common/timers.c b/src/common/timers.c
index c8e09414f..93cde7de5 100644
--- a/src/common/timers.c
+++ b/src/common/timers.c
@@ -245,7 +245,7 @@ timer_new(timer_cb_fn_t cb, void *arg)
* scheduled.
*/
void
-timer_free(tor_timer_t *t)
+timer_free_(tor_timer_t *t)
{
if (! t)
return;
diff --git a/src/common/timers.h b/src/common/timers.h
index d4d4fb00a..6c9594d31 100644
--- a/src/common/timers.h
+++ b/src/common/timers.h
@@ -17,7 +17,8 @@ void timer_get_cb(const tor_timer_t *t,
timer_cb_fn_t *cb_out, void **arg_out);
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);
+void timer_free_(tor_timer_t *t);
+#define timer_free(t) FREE_AND_NULL(timer, (t))
void timers_initialize(void);
void timers_shutdown(void);
diff --git a/src/common/util.c b/src/common/util.c
index 7dc5e8144..67e97811c 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -4713,7 +4713,7 @@ environment_variable_names_equal(const char *s1, const char *s2)
/** Free <b>env</b> (assuming it was produced by
* process_environment_make). */
void
-process_environment_free(process_environment_t *env)
+process_environment_free_(process_environment_t *env)
{
if (env == NULL) return;
diff --git a/src/common/util.h b/src/common/util.h
index e11265a5d..c5bd3f0bd 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -431,7 +431,9 @@ struct process_environment_t {
};
process_environment_t *process_environment_make(struct smartlist_t *env_vars);
-void process_environment_free(process_environment_t *env);
+void process_environment_free_(process_environment_t *env);
+#define process_environment_free(env) \
+ FREE_AND_NULL(process_environment, (env))
struct smartlist_t *get_current_process_environment_variables(void);
diff --git a/src/or/channel.h b/src/or/channel.h
index 32336fe1d..e23d70791 100644
--- a/src/or/channel.h
+++ b/src/or/channel.h
@@ -719,6 +719,8 @@ int packed_cell_is_destroy(channel_t *chan,
/* Declare the handle helpers */
HANDLE_DECL(channel, channel_s,)
+#define channel_handle_free(h) \
+ FREE_AND_NULL(channel_handle, (h))
#endif /* !defined(TOR_CHANNEL_H) */
diff --git a/src/or/conscache.h b/src/or/conscache.h
index 3c89dedf4..e4f308fa4 100644
--- a/src/or/conscache.h
+++ b/src/or/conscache.h
@@ -10,6 +10,8 @@ typedef struct consensus_cache_entry_t consensus_cache_entry_t;
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, (h))
consensus_cache_t *consensus_cache_open(const char *subdir, int max_entries);
void consensus_cache_free(consensus_cache_t *cache);
diff --git a/src/or/entrynodes.h b/src/or/entrynodes.h
index 3ca966bc7..d7f4967a0 100644
--- a/src/or/entrynodes.h
+++ b/src/or/entrynodes.h
@@ -476,6 +476,9 @@ STATIC double get_meaningful_restriction_threshold(void);
STATIC double get_extreme_restriction_threshold(void);
HANDLE_DECL(entry_guard, entry_guard_t, STATIC)
+#define entry_guard_handle_free(h) \
+ FREE_AND_NULL(entry_guard_handle, (h))
+
STATIC guard_selection_type_t guard_selection_infer_type(
guard_selection_type_t type_in,
const char *name);
diff --git a/src/or/policies.c b/src/or/policies.c
index 1f8013071..2e584095d 100644
--- a/src/or/policies.c
+++ b/src/or/policies.c
@@ -1792,14 +1792,14 @@ policies_parse_exit_policy_reject_private(
/* Reject public IPv4 addresses on any interface */
public_addresses = get_interface_address6_list(LOG_INFO, AF_INET, 0);
addr_policy_append_reject_addr_list_filter(dest, public_addresses, 1, 0);
- free_interface_address6_list(public_addresses);
+ interface_address6_list_free(public_addresses);
/* Don't look for IPv6 addresses if we're configured as IPv4-only */
if (ipv6_exit) {
/* Reject public IPv6 addresses on any interface */
public_addresses = get_interface_address6_list(LOG_INFO, AF_INET6, 0);
addr_policy_append_reject_addr_list_filter(dest, public_addresses, 0, 1);
- free_interface_address6_list(public_addresses);
+ interface_address6_list_free(public_addresses);
}
}
diff --git a/src/test/test-timers.c b/src/test/test-timers.c
index 99715f433..a0b5b535c 100644
--- a/src/test/test-timers.c
+++ b/src/test/test-timers.c
@@ -133,7 +133,7 @@ main(int argc, char **argv)
ret = 0;
}
- timer_free(NULL);
+ timer_free_(NULL);
for (i = 0; i < N_TIMERS; ++i) {
timer_free(timers[i]);
diff --git a/src/test/test_address.c b/src/test/test_address.c
index f36ff6998..9c88d37a4 100644
--- a/src/test/test_address.c
+++ b/src/test/test_address.c
@@ -763,7 +763,7 @@ test_address_get_if_addrs_list_internal(void *arg)
tt_assert(!smartlist_contains_ipv6_tor_addr(results));
done:
- free_interface_address_list(results);
+ interface_address_list_free(results);
return;
}
@@ -792,7 +792,7 @@ test_address_get_if_addrs_list_no_internal(void *arg)
tt_assert(!smartlist_contains_ipv6_tor_addr(results));
done:
- free_interface_address_list(results);
+ interface_address_list_free(results);
return;
}
@@ -834,7 +834,7 @@ test_address_get_if_addrs6_list_internal(void *arg)
}
done:
- free_interface_address6_list(results);
+ interface_address6_list_free(results);
teardown_capture_of_logs();
return;
}
@@ -878,7 +878,7 @@ test_address_get_if_addrs6_list_no_internal(void *arg)
done:
teardown_capture_of_logs();
- free_interface_address6_list(results);
+ interface_address6_list_free(results);
return;
}
@@ -943,8 +943,8 @@ test_address_get_if_addrs_internal_fail(void *arg)
done:
UNMOCK(get_interface_addresses_raw);
UNMOCK(get_interface_address6_via_udp_socket_hack);
- free_interface_address6_list(results1);
- free_interface_address6_list(results2);
+ interface_address6_list_free(results1);
+ interface_address6_list_free(results2);
return;
}
@@ -971,8 +971,8 @@ test_address_get_if_addrs_no_internal_fail(void *arg)
done:
UNMOCK(get_interface_addresses_raw);
UNMOCK(get_interface_address6_via_udp_socket_hack);
- free_interface_address6_list(results1);
- free_interface_address6_list(results2);
+ interface_address6_list_free(results1);
+ interface_address6_list_free(results2);
return;
}
diff --git a/src/test/test_handles.c b/src/test/test_handles.c
index 7ddee6e37..03ae0883c 100644
--- a/src/test/test_handles.c
+++ b/src/test/test_handles.c
@@ -13,6 +13,8 @@ typedef struct demo_t {
} demo_t;
HANDLE_DECL(demo, demo_t, static)
+#define demo_handle_free(h) \
+ FREE_AND_NULL(demo_handle, (h))
HANDLE_IMPL(demo, demo_t, static)
static demo_t *
diff --git a/src/test/test_policy.c b/src/test/test_policy.c
index 83dca2d43..f8aa8ac40 100644
--- a/src/test/test_policy.c
+++ b/src/test/test_policy.c
@@ -1318,7 +1318,7 @@ mock_get_interface_address6_list(int severity,
return clone_list;
done:
- free_interface_address6_list(clone_list);
+ interface_address6_list_free(clone_list);
return NULL;
}
@@ -1393,11 +1393,11 @@ test_policies_reject_interface_address(void *arg)
done:
addr_policy_list_free(policy);
- free_interface_address6_list(public_ipv4_addrs);
- free_interface_address6_list(public_ipv6_addrs);
+ interface_address6_list_free(public_ipv4_addrs);
+ interface_address6_list_free(public_ipv6_addrs);
UNMOCK(get_interface_address6_list);
- /* we don't use free_interface_address6_list on these lists because their
+ /* we don't use interface_address6_list_free on these lists because their
* address pointers are stack-based */
smartlist_free(mock_ipv4_addrs);
smartlist_free(mock_ipv6_addrs);
1
0
08 Dec '17
commit 95531ddfbfb6cb30760523d91fd4dfc966d2f6a5
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Thu Dec 7 10:37:59 2017 -0500
Let's have only one FREE_AND_NULL variant.
This commit removes the old FREE_AND_NULL, and renames the old
FREE_AND_NULL_UNMATCHED so that it is now called FREE_AND_NULL.
This will break all the FREE_AND_NULL_* users; the next commit will
fix them.
---
src/common/util.h | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/src/common/util.h b/src/common/util.h
index e85be57c0..97ad15f83 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -121,11 +121,8 @@ 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) \
+#define FREE_AND_NULL(typename, freefn, var) \
do { \
/* only evaluate (var) once. */ \
typename **tmp__free__ptr ## freefn = &(var); \
@@ -133,11 +130,6 @@ void tor_log_mallinfo(int severity);
(*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) \
- 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:
* <pre>
1
0