Update free functions into macros: src/or/ part 1

This covers addressmap.h (no change needed) through confparse.h
This commit is contained in:
Nick Mathewson 2017-11-21 08:29:42 -05:00
parent c92ac9f5cb
commit b0cc9856ee
19 changed files with 75 additions and 63 deletions

View file

@ -1,3 +1,4 @@
/* * Copyright (c) 2012-2017, The Tor Project, Inc. */
/* See LICENSE for licensing information */
@ -979,7 +980,7 @@ channel_init_listener(channel_listener_t *chan_l)
*/
void
channel_free(channel_t *chan)
channel_free_(channel_t *chan)
{
if (!chan) return;
@ -1034,7 +1035,7 @@ channel_free(channel_t *chan)
*/
void
channel_listener_free(channel_listener_t *chan_l)
channel_listener_free_(channel_listener_t *chan_l)
{
if (!chan_l) return;

View file

@ -516,8 +516,10 @@ void channel_listener_close_for_error(channel_listener_t *chan_l);
void channel_listener_closed(channel_listener_t *chan_l);
/* Free a channel */
void channel_free(channel_t *chan);
void channel_listener_free(channel_listener_t *chan_l);
void channel_free_(channel_t *chan);
#define channel_free(chan) FREE_AND_NULL(channel, (chan))
void channel_listener_free_(channel_listener_t *chan_l);
#define channel_listener_free(chan_l) FREE_AND_NULL(channel_listener, (chan_l))
/* State/metadata setters */

View file

@ -2729,7 +2729,7 @@ extend_info_from_node(const node_t *node, int for_direct_connect)
/** Release storage held by an extend_info_t struct. */
void
extend_info_free(extend_info_t *info)
extend_info_free_(extend_info_t *info)
{
if (!info)
return;

View file

@ -58,7 +58,8 @@ extend_info_t *extend_info_new(const char *nickname,
const tor_addr_t *addr, uint16_t port);
extend_info_t *extend_info_from_node(const node_t *r, int for_direct_connect);
extend_info_t *extend_info_dup(extend_info_t *info);
void extend_info_free(extend_info_t *info);
void extend_info_free_(extend_info_t *info);
#define extend_info_free(info) FREE_AND_NULL(extend_info, (info))
int extend_info_addr_is_allowed(const tor_addr_t *addr);
int extend_info_supports_tap(const extend_info_t* ei);
int extend_info_supports_ntor(const extend_info_t* ei);

View file

@ -924,7 +924,7 @@ circuit_clear_testing_cell_stats(circuit_t *circ)
/** Deallocate space associated with circ.
*/
STATIC void
circuit_free(circuit_t *circ)
circuit_free_(circuit_t *circ)
{
circid_t n_circ_id = 0;
void *mem;

View file

@ -81,7 +81,8 @@ MOCK_DECL(void, channel_note_destroy_not_pending,
smartlist_t *circuit_find_circuits_to_upgrade_from_guard_wait(void);
#ifdef CIRCUITLIST_PRIVATE
STATIC void circuit_free(circuit_t *circ);
STATIC void circuit_free_(circuit_t *circ);
#define circuit_free(circ) FREE_AND_NULL(circuit, (circ))
STATIC size_t n_cells_in_circ_queues(const circuit_t *c);
STATIC uint32_t circuit_max_queued_data_age(const circuit_t *c, uint32_t now);
STATIC uint32_t circuit_max_queued_cell_age(const circuit_t *c, uint32_t now);

View file

@ -546,7 +546,7 @@ circuitmux_mark_destroyed_circids_usable(circuitmux_t *cmux, channel_t *chan)
*/
void
circuitmux_free(circuitmux_t *cmux)
circuitmux_free_(circuitmux_t *cmux)
{
if (!cmux) return;

View file

@ -104,7 +104,8 @@ void circuitmux_assert_okay(circuitmux_t *cmux);
circuitmux_t * circuitmux_alloc(void);
void circuitmux_detach_all_circuits(circuitmux_t *cmux,
smartlist_t *detached_out);
void circuitmux_free(circuitmux_t *cmux);
void circuitmux_free_(circuitmux_t *cmux);
#define circuitmux_free(cmux) FREE_AND_NULL(circuitmux, (cmux))
/* Policy control */
void circuitmux_clear_policy(circuitmux_t *cmux);

View file

@ -5739,7 +5739,7 @@ validate_transport_socks_arguments(const smartlist_t *args)
/** Deallocate a bridge_line_t structure. */
/* private */ void
bridge_line_free(bridge_line_t *bridge_line)
bridge_line_free_(bridge_line_t *bridge_line)
{
if (!bridge_line)
return;

View file

@ -152,7 +152,8 @@ typedef struct bridge_line_t {
transport proxy. */
} bridge_line_t;
void bridge_line_free(bridge_line_t *bridge_line);
void bridge_line_free_(bridge_line_t *bridge_line);
#define bridge_line_free(line) FREE_AND_NULL(bridge_line, (line))
bridge_line_t *parse_bridge_line(const char *line);
smartlist_t *get_options_from_transport_options_line(const char *line,
const char *transport);

View file

@ -863,7 +863,7 @@ config_reset(const config_format_t *fmt, void *options,
/** Release storage held by <b>options</b>. */
void
config_free(const config_format_t *fmt, void *options)
config_free_(const config_format_t *fmt, void *options)
{
int i;

View file

@ -177,7 +177,12 @@ typedef struct config_format_t {
#define CAL_WARN_DEPRECATIONS (1u<<2)
void *config_new(const config_format_t *fmt);
void config_free(const config_format_t *fmt, void *options);
void config_free_(const config_format_t *fmt, void *options);
#define config_free(fmt, options) do { \
config_free_((fmt), (options)); \
(options) = NULL; \
} while (0)
config_line_t *config_get_assigned_option(const config_format_t *fmt,
const void *options, const char *key,
int escape_val);

View file

@ -345,8 +345,8 @@ test_onion_queues(void *arg)
tt_int_op(0,OP_EQ, onion_num_pending(ONION_HANDSHAKE_TYPE_NTOR));
done:
circuit_free(TO_CIRCUIT(circ1));
circuit_free(TO_CIRCUIT(circ2));
circuit_free_(TO_CIRCUIT(circ1));
circuit_free_(TO_CIRCUIT(circ2));
tor_free(create1);
tor_free(create2);
tor_free(onionskin);

View file

@ -130,8 +130,8 @@ test_circuit_n_cells(void *arg)
tt_int_op(n_cells_in_circ_queues(TO_CIRCUIT(origin_c)), OP_EQ, 2);
done:
circuit_free(TO_CIRCUIT(or_c));
circuit_free(TO_CIRCUIT(origin_c));
circuit_free_(TO_CIRCUIT(or_c));
circuit_free_(TO_CIRCUIT(origin_c));
}
struct testcase_t cell_queue_tests[] = {

View file

@ -141,7 +141,7 @@ test_clist_maps(void *arg)
/* Okay, now free ch2 and make sure that the circuit ID is STILL not
* usable, because we haven't declared the destroy to be nonpending */
tt_int_op(cdm.ncalls, OP_EQ, 0);
circuit_free(TO_CIRCUIT(or_c2));
circuit_free_(TO_CIRCUIT(or_c2));
or_c2 = NULL; /* prevent free */
tt_int_op(cdm.ncalls, OP_EQ, 2);
memset(&cdm, 0, sizeof(cdm));
@ -160,9 +160,9 @@ test_clist_maps(void *arg)
done:
if (or_c1)
circuit_free(TO_CIRCUIT(or_c1));
circuit_free_(TO_CIRCUIT(or_c1));
if (or_c2)
circuit_free(TO_CIRCUIT(or_c2));
circuit_free_(TO_CIRCUIT(or_c2));
if (ch1)
tor_free(ch1->cmux);
if (ch2)
@ -234,11 +234,11 @@ test_rend_token_maps(void *arg)
/* Marking a circuit makes it not get returned any more */
circuit_mark_for_close(TO_CIRCUIT(c1), END_CIRC_REASON_FINISHED);
tt_ptr_op(NULL, OP_EQ, hs_circuitmap_get_rend_circ_relay_side(tok1));
circuit_free(TO_CIRCUIT(c1));
circuit_free_(TO_CIRCUIT(c1));
c1 = NULL;
/* Freeing a circuit makes it not get returned any more. */
circuit_free(TO_CIRCUIT(c2));
circuit_free_(TO_CIRCUIT(c2));
c2 = NULL;
tt_ptr_op(NULL, OP_EQ, hs_circuitmap_get_intro_circ_v2_relay_side(tok2));
@ -275,15 +275,15 @@ test_rend_token_maps(void *arg)
done:
if (c1)
circuit_free(TO_CIRCUIT(c1));
circuit_free_(TO_CIRCUIT(c1));
if (c2)
circuit_free(TO_CIRCUIT(c2));
circuit_free_(TO_CIRCUIT(c2));
if (c3)
circuit_free(TO_CIRCUIT(c3));
circuit_free_(TO_CIRCUIT(c3));
if (c4)
circuit_free(TO_CIRCUIT(c4));
circuit_free_(TO_CIRCUIT(c4));
if (c5)
circuit_free(TO_CIRCUIT(c5));
circuit_free_(TO_CIRCUIT(c5));
}
static void
@ -452,10 +452,10 @@ test_hs_circuitmap_isolation(void *arg)
}
done:
circuit_free(TO_CIRCUIT(circ1));
circuit_free(TO_CIRCUIT(circ2));
circuit_free(TO_CIRCUIT(circ3));
circuit_free(TO_CIRCUIT(circ4));
circuit_free_(TO_CIRCUIT(circ1));
circuit_free_(TO_CIRCUIT(circ2));
circuit_free_(TO_CIRCUIT(circ3));
circuit_free_(TO_CIRCUIT(circ4));
}
struct testcase_t circuitlist_tests[] = {

View file

@ -2372,8 +2372,8 @@ upgrade_circuits_cleanup(const struct testcase_t *testcase, void *ptr)
// circuit_guard_state_free(data->guard2_state); // held in circ2
guard_selection_free(data->gs);
smartlist_free(data->all_origin_circuits);
circuit_free(TO_CIRCUIT(data->circ1));
circuit_free(TO_CIRCUIT(data->circ2));
circuit_free_(TO_CIRCUIT(data->circ1));
circuit_free_(TO_CIRCUIT(data->circ2));
tor_free(data);
return big_fake_network_cleanup(testcase, NULL);
}

View file

@ -230,7 +230,7 @@ test_e2e_rend_circuit_setup_legacy(void *arg)
connection_free_(conn);
if (or_circ)
tor_free(TO_CIRCUIT(or_circ)->n_chan);
circuit_free(TO_CIRCUIT(or_circ));
circuit_free_(TO_CIRCUIT(or_circ));
}
/* Test: Ensure that setting up v3 rendezvous circuits works correctly. */
@ -300,7 +300,7 @@ test_e2e_rend_circuit_setup(void *arg)
connection_free_(conn);
if (or_circ)
tor_free(TO_CIRCUIT(or_circ)->n_chan);
circuit_free(TO_CIRCUIT(or_circ));
circuit_free_(TO_CIRCUIT(or_circ));
}
/** Test client logic for picking intro points from a descriptor. Also test how

View file

@ -194,7 +194,7 @@ test_establish_intro_wrong_purpose(void *arg)
tt_int_op(retval, OP_EQ, -1);
done:
circuit_free(TO_CIRCUIT(intro_circ));
circuit_free_(TO_CIRCUIT(intro_circ));
}
/* Prepare a circuit for accepting an ESTABLISH_INTRO cell */
@ -228,7 +228,7 @@ test_establish_intro_wrong_keytype(void *arg)
tt_int_op(retval, OP_EQ, -1);
done:
circuit_free(TO_CIRCUIT(intro_circ));
circuit_free_(TO_CIRCUIT(intro_circ));
}
/* Send an ESTABLISH_INTRO cell with an unknown auth key type. Should fail. */
@ -263,7 +263,7 @@ test_establish_intro_wrong_keytype2(void *arg)
tt_int_op(retval, OP_EQ, -1);
done:
circuit_free(TO_CIRCUIT(intro_circ));
circuit_free_(TO_CIRCUIT(intro_circ));
}
/* Send a legit ESTABLISH_INTRO cell but with a wrong MAC. Should fail. */
@ -333,7 +333,7 @@ test_establish_intro_wrong_mac(void *arg)
done:
trn_cell_establish_intro_free(cell);
circuit_free(TO_CIRCUIT(intro_circ));
circuit_free_(TO_CIRCUIT(intro_circ));
}
/* Send a legit ESTABLISH_INTRO cell but with a wrong auth key length. Should
@ -378,7 +378,7 @@ test_establish_intro_wrong_auth_key_len(void *arg)
done:
trn_cell_establish_intro_free(cell);
circuit_free(TO_CIRCUIT(intro_circ));
circuit_free_(TO_CIRCUIT(intro_circ));
}
/* Send a legit ESTABLISH_INTRO cell but with a wrong sig length. Should
@ -423,7 +423,7 @@ test_establish_intro_wrong_sig_len(void *arg)
done:
trn_cell_establish_intro_free(cell);
circuit_free(TO_CIRCUIT(intro_circ));
circuit_free_(TO_CIRCUIT(intro_circ));
}
/* Send a legit ESTABLISH_INTRO cell but slightly change the signature. Should
@ -460,7 +460,7 @@ test_establish_intro_wrong_sig(void *arg)
tt_int_op(retval, OP_EQ, -1);
done:
circuit_free(TO_CIRCUIT(intro_circ));
circuit_free_(TO_CIRCUIT(intro_circ));
}
/* Helper function: Send a well-formed v3 ESTABLISH_INTRO cell to
@ -629,8 +629,8 @@ test_intro_point_registration(void *arg)
done:
crypto_pk_free(legacy_auth_key);
circuit_free(TO_CIRCUIT(intro_circ));
circuit_free(TO_CIRCUIT(legacy_intro_circ));
circuit_free_(TO_CIRCUIT(intro_circ));
circuit_free_(TO_CIRCUIT(legacy_intro_circ));
trn_cell_establish_intro_free(establish_intro_cell);
test_circuitmap_free_all();
@ -650,7 +650,7 @@ test_introduce1_suitable_circuit(void *arg)
circ = or_circuit_new(0, NULL);
circuit_change_purpose(TO_CIRCUIT(circ), CIRCUIT_PURPOSE_OR);
ret = circuit_is_suitable_for_introduce1(circ);
circuit_free(TO_CIRCUIT(circ));
circuit_free_(TO_CIRCUIT(circ));
tt_int_op(ret, OP_EQ, 1);
}
@ -659,7 +659,7 @@ test_introduce1_suitable_circuit(void *arg)
circ = or_circuit_new(0, NULL);
circuit_change_purpose(TO_CIRCUIT(circ), CIRCUIT_PURPOSE_INTRO_POINT);
ret = circuit_is_suitable_for_introduce1(circ);
circuit_free(TO_CIRCUIT(circ));
circuit_free_(TO_CIRCUIT(circ));
tt_int_op(ret, OP_EQ, 0);
}
@ -670,7 +670,7 @@ test_introduce1_suitable_circuit(void *arg)
/* Bogus pointer, the check is against NULL on n_chan. */
circ->base_.n_chan = (channel_t *) circ;
ret = circuit_is_suitable_for_introduce1(circ);
circuit_free(TO_CIRCUIT(circ));
circuit_free_(TO_CIRCUIT(circ));
tt_int_op(ret, OP_EQ, 0);
}
@ -681,7 +681,7 @@ test_introduce1_suitable_circuit(void *arg)
circuit_change_purpose(TO_CIRCUIT(circ), CIRCUIT_PURPOSE_OR);
circ->already_received_introduce1 = 1;
ret = circuit_is_suitable_for_introduce1(circ);
circuit_free(TO_CIRCUIT(circ));
circuit_free_(TO_CIRCUIT(circ));
tt_int_op(ret, OP_EQ, 0);
}
@ -800,7 +800,7 @@ test_received_introduce1_handling(void *arg)
circ = helper_create_intro_circuit();
ret = hs_intro_received_introduce1(circ, buf, DIGEST_LEN - 1);
tt_int_op(ret, OP_EQ, -1);
circuit_free(TO_CIRCUIT(circ));
circuit_free_(TO_CIRCUIT(circ));
}
/* We have a unit test only for the suitability of a circuit to receive an
@ -813,7 +813,7 @@ test_received_introduce1_handling(void *arg)
memset(test, 0, sizeof(test));
ret = handle_introduce1(circ, test, sizeof(test));
tor_free(circ->p_chan);
circuit_free(TO_CIRCUIT(circ));
circuit_free_(TO_CIRCUIT(circ));
tt_int_op(ret, OP_EQ, -1);
}
@ -838,8 +838,8 @@ test_received_introduce1_handling(void *arg)
memcpy(auth_key.pubkey, cell_auth_key, ED25519_PUBKEY_LEN);
hs_circuitmap_register_intro_circ_v3_relay_side(service_circ, &auth_key);
ret = hs_intro_received_introduce1(circ, request, request_len);
circuit_free(TO_CIRCUIT(circ));
circuit_free(TO_CIRCUIT(service_circ));
circuit_free_(TO_CIRCUIT(circ));
circuit_free_(TO_CIRCUIT(service_circ));
tt_int_op(ret, OP_EQ, 0);
}
@ -867,8 +867,8 @@ test_received_introduce1_handling(void *arg)
memcpy(token, legacy_key_id, sizeof(token));
hs_circuitmap_register_intro_circ_v2_relay_side(service_circ, token);
ret = hs_intro_received_introduce1(circ, request, request_len);
circuit_free(TO_CIRCUIT(circ));
circuit_free(TO_CIRCUIT(service_circ));
circuit_free_(TO_CIRCUIT(circ));
circuit_free_(TO_CIRCUIT(service_circ));
tt_int_op(ret, OP_EQ, 0);
}

View file

@ -182,7 +182,7 @@ test_e2e_rend_circuit_setup(void *arg)
tt_int_op(or_circ->base_.purpose, OP_EQ, CIRCUIT_PURPOSE_S_REND_JOINED);
done:
circuit_free(TO_CIRCUIT(or_circ));
circuit_free_(TO_CIRCUIT(or_circ));
}
/* Helper: Return a newly allocated and initialized origin circuit with
@ -655,7 +655,7 @@ test_intro_circuit_opened(void *arg)
teardown_capture_of_logs();
done:
circuit_free(TO_CIRCUIT(circ));
circuit_free_(TO_CIRCUIT(circ));
hs_free_all();
UNMOCK(circuit_mark_for_close_);
UNMOCK(relay_send_command_from_edge_);
@ -730,7 +730,7 @@ test_intro_established(void *arg)
done:
if (circ)
circuit_free(TO_CIRCUIT(circ));
circuit_free_(TO_CIRCUIT(circ));
hs_free_all();
UNMOCK(circuit_mark_for_close_);
}
@ -772,7 +772,7 @@ test_rdv_circuit_opened(void *arg)
tt_int_op(TO_CIRCUIT(circ)->purpose, OP_EQ, CIRCUIT_PURPOSE_S_REND_JOINED);
done:
circuit_free(TO_CIRCUIT(circ));
circuit_free_(TO_CIRCUIT(circ));
hs_free_all();
UNMOCK(circuit_mark_for_close_);
UNMOCK(relay_send_command_from_edge_);
@ -852,7 +852,7 @@ test_introduce2(void *arg)
or_state_free(dummy_state);
dummy_state = NULL;
if (circ)
circuit_free(TO_CIRCUIT(circ));
circuit_free_(TO_CIRCUIT(circ));
hs_free_all();
UNMOCK(circuit_mark_for_close_);
}
@ -936,7 +936,7 @@ test_service_event(void *arg)
done:
hs_circuitmap_remove_circuit(TO_CIRCUIT(circ));
circuit_free(TO_CIRCUIT(circ));
circuit_free_(TO_CIRCUIT(circ));
hs_free_all();
UNMOCK(circuit_mark_for_close_);
}
@ -1490,8 +1490,8 @@ test_rendezvous1_parsing(void *arg)
* would need an extra circuit and some more stuff but it's doable. */
done:
circuit_free(TO_CIRCUIT(service_circ));
circuit_free(TO_CIRCUIT(client_circ));
circuit_free_(TO_CIRCUIT(service_circ));
circuit_free_(TO_CIRCUIT(client_circ));
hs_service_free(service);
hs_free_all();
UNMOCK(relay_send_command_from_edge_);