Commit 0c1b3070 authored by Nick Mathewson's avatar Nick Mathewson 🐻
Browse files

Now that FOO_free(NULL) always works, remove checks before calling it.

parent 79f72d0e
......@@ -165,9 +165,7 @@ tor_gzip_compress(char **out, size_t *out_len,
deflateEnd(stream);
tor_free(stream);
}
if (*out) {
tor_free(*out);
}
return -1;
}
......
......@@ -1314,9 +1314,7 @@ log_cert_lifetime(X509 *cert, const char *problem)
tls_log_errors(NULL, LOG_WARN, LD_NET, "getting certificate lifetime");
if (bio)
BIO_free(bio);
if (s1)
tor_free(s1);
if (s2)
tor_free(s2);
}
......
......@@ -953,7 +953,6 @@ const char *
escaped(const char *s)
{
static char *_escaped_val = NULL;
if (_escaped_val)
tor_free(_escaped_val);
if (s)
......
......@@ -364,7 +364,7 @@ circuit_build_times_update_state(circuit_build_times_t *cbt,
or_state_mark_dirty(get_or_state(), 0);
}
if (histogram) tor_free(histogram);
tor_free(histogram);
}
/**
......@@ -1819,10 +1819,9 @@ circuit_finish_handshake(origin_circuit_t *circ, uint8_t reply_type,
return -END_CIRC_REASON_TORPROTOCOL;
}
if (hop->dh_handshake_state) {
crypto_dh_free(hop->dh_handshake_state); /* don't need it anymore */
hop->dh_handshake_state = NULL;
}
memset(hop->fast_handshake_state, 0, sizeof(hop->fast_handshake_state));
if (circuit_init_cpath_crypto(hop, keys, 0)<0) {
......@@ -2430,7 +2429,6 @@ circuit_append_new_exit(origin_circuit_t *circ, extend_info_t *exit)
state = circ->build_state;
tor_assert(state);
if (state->chosen_exit)
extend_info_free(state->chosen_exit);
state->chosen_exit = extend_info_dup(exit);
......@@ -2746,7 +2744,6 @@ extend_info_free(extend_info_t *info)
{
if (!info)
return;
if (info->onion_key)
crypto_free_pk_env(info->onion_key);
tor_free(info);
}
......
......@@ -451,17 +451,14 @@ circuit_free(circuit_t *circ)
memlen = sizeof(origin_circuit_t);
tor_assert(circ->magic == ORIGIN_CIRCUIT_MAGIC);
if (ocirc->build_state) {
if (ocirc->build_state->chosen_exit)
extend_info_free(ocirc->build_state->chosen_exit);
if (ocirc->build_state->pending_final_cpath)
circuit_free_cpath_node(ocirc->build_state->pending_final_cpath);
}
tor_free(ocirc->build_state);
circuit_free_cpath(ocirc->cpath);
if (ocirc->intro_key)
crypto_free_pk_env(ocirc->intro_key);
if (ocirc->rend_data)
rend_data_free(ocirc->rend_data);
} else {
or_circuit_t *ocirc = TO_OR_CIRCUIT(circ);
......@@ -472,13 +469,9 @@ circuit_free(circuit_t *circ)
memlen = sizeof(or_circuit_t);
tor_assert(circ->magic == OR_CIRCUIT_MAGIC);
if (ocirc->p_crypto)
crypto_free_cipher_env(ocirc->p_crypto);
if (ocirc->p_digest)
crypto_free_digest_env(ocirc->p_digest);
if (ocirc->n_crypto)
crypto_free_cipher_env(ocirc->n_crypto);
if (ocirc->n_digest)
crypto_free_digest_env(ocirc->n_digest);
if (ocirc->rend_splice) {
......@@ -495,7 +488,6 @@ circuit_free(circuit_t *circ)
cell_queue_clear(&ocirc->p_conn_cells);
}
if (circ->n_hop)
extend_info_free(circ->n_hop);
tor_free(circ->n_conn_onionskin);
......@@ -549,10 +541,10 @@ circuit_free_all(void)
circuit_free(global_circuitlist);
global_circuitlist = next;
}
if (circuits_pending_or_conns) {
smartlist_free(circuits_pending_or_conns);
circuits_pending_or_conns = NULL;
}
HT_CLEAR(orconn_circid_map, &orconn_circid_circuit_map);
}
......@@ -563,17 +555,11 @@ circuit_free_cpath_node(crypt_path_t *victim)
if (!victim)
return;
if (victim->f_crypto)
crypto_free_cipher_env(victim->f_crypto);
if (victim->b_crypto)
crypto_free_cipher_env(victim->b_crypto);
if (victim->f_digest)
crypto_free_digest_env(victim->f_digest);
if (victim->b_digest)
crypto_free_digest_env(victim->b_digest);
if (victim->dh_handshake_state)
crypto_dh_free(victim->dh_handshake_state);
if (victim->extend_info)
extend_info_free(victim->extend_info);
memset(victim, 0xBB, sizeof(crypt_path_t)); /* poison memory */
......
......@@ -928,7 +928,7 @@ circuit_launch_by_router(uint8_t purpose,
if (exit)
info = extend_info_from_router(exit);
circ = circuit_launch_by_extend_info(purpose, info, flags);
if (info)
extend_info_free(info);
return circ;
}
......@@ -1222,7 +1222,6 @@ circuit_get_open_circ_or_launch(edge_connection_t *conn,
flags);
}
if (extend_info)
extend_info_free(extend_info);
if (desired_circuit_purpose != CIRCUIT_PURPOSE_C_GENERAL) {
......
......@@ -827,7 +827,7 @@ set_options(or_options_t *new_val, char **msg)
"Acting on config options left us in a broken state. Dying.");
exit(1);
}
if (old_options)
config_free(&options_format, old_options);
return 0;
......@@ -862,7 +862,6 @@ or_options_free(or_options_t *options)
if (!options)
return;
if (options->_ExcludeExitNodesUnion)
routerset_free(options->_ExcludeExitNodesUnion);
config_free(&options_format, options);
}
......@@ -872,18 +871,15 @@ or_options_free(or_options_t *options)
void
config_free_all(void)
{
if (global_options) {
or_options_free(global_options);
global_options = NULL;
}
if (global_state) {
config_free(&state_format, global_state);
global_state = NULL;
}
if (global_cmdline_options) {
config_free_lines(global_cmdline_options);
global_cmdline_options = NULL;
}
tor_free(torrc_fname);
tor_free(_version);
tor_free(global_dirfrontpagecontents);
......@@ -5089,7 +5085,6 @@ or_state_set(or_state_t *new_state)
{
char *err = NULL;
tor_assert(new_state);
if (global_state)
config_free(&state_format, global_state);
global_state = new_state;
if (entry_guards_parse_state(global_state, 1, &err)<0) {
......
......@@ -371,14 +371,10 @@ _connection_free(connection_t *conn)
if (connection_speaks_cells(conn)) {
or_connection_t *or_conn = TO_OR_CONN(conn);
if (or_conn->tls) {
tor_tls_free(or_conn->tls);
or_conn->tls = NULL;
}
if (or_conn->handshake_state) {
or_handshake_state_free(or_conn->handshake_state);
or_conn->handshake_state = NULL;
}
tor_free(or_conn->nickname);
}
if (CONN_IS_EDGE(conn)) {
......@@ -388,7 +384,7 @@ _connection_free(connection_t *conn)
memset(edge_conn->socks_request, 0xcc, sizeof(socks_request_t));
tor_free(edge_conn->socks_request);
}
if (edge_conn->rend_data)
rend_data_free(edge_conn->rend_data);
}
if (conn->type == CONN_TYPE_CONTROL) {
......@@ -402,15 +398,14 @@ _connection_free(connection_t *conn)
if (conn->type == CONN_TYPE_DIR) {
dir_connection_t *dir_conn = TO_DIR_CONN(conn);
tor_free(dir_conn->requested_resource);
if (dir_conn->zlib_state)
tor_zlib_free(dir_conn->zlib_state);
if (dir_conn->fingerprint_stack) {
SMARTLIST_FOREACH(dir_conn->fingerprint_stack, char *, cp, tor_free(cp));
smartlist_free(dir_conn->fingerprint_stack);
}
if (dir_conn->cached_dir)
cached_dir_decref(dir_conn->cached_dir);
if (dir_conn->rend_data)
rend_data_free(dir_conn->rend_data);
}
......
......@@ -795,14 +795,11 @@ addressmap_clean(time_t now)
void
addressmap_free_all(void)
{
if (addressmap) {
strmap_free(addressmap, addressmap_ent_free);
addressmap = NULL;
}
if (virtaddress_reversemap) {
strmap_free(virtaddress_reversemap, addressmap_virtaddress_ent_free);
virtaddress_reversemap = NULL;
}
}
/** Look at address, and rewrite it until it doesn't want any
......
......@@ -80,10 +80,9 @@ connection_or_clear_identity_map(void)
}
});
if (orconn_identity_map) {
digestmap_free(orconn_identity_map, NULL);
orconn_identity_map = NULL;
}
}
/** Change conn->identity_digest to digest, and add conn into
......@@ -1118,10 +1117,10 @@ connection_or_set_state_open(or_connection_t *conn)
}
}
}
if (conn->handshake_state) {
or_handshake_state_free(conn->handshake_state);
conn->handshake_state = NULL;
}
connection_start_reading(TO_CONN(conn));
circuit_n_conn_done(conn, 1); /* send the pending creates, if any. */
......
......@@ -2143,7 +2143,6 @@ handle_control_extendcircuit(control_connection_t *conn, uint32_t len,
done:
SMARTLIST_FOREACH(router_nicknames, char *, n, tor_free(n));
smartlist_free(router_nicknames);
if (routers)
smartlist_free(routers);
return 0;
}
......
......@@ -2818,9 +2818,7 @@ generate_v2_networkstatus_opinion(void)
tor_free(status);
tor_free(hostname);
tor_free(identity_pkey);
if (routers)
smartlist_free(routers);
if (omit_as_sybil)
digestmap_free(omit_as_sybil, NULL);
return r;
}
......@@ -3497,7 +3495,6 @@ connection_dirserv_add_networkstatus_bytes_to_outbuf(dir_connection_t *conn)
}
} else {
connection_dirserv_finish_spooling(conn);
if (conn->fingerprint_stack)
smartlist_free(conn->fingerprint_stack);
conn->fingerprint_stack = NULL;
return 0;
......@@ -3545,13 +3542,10 @@ dirserv_free_all(void)
cached_dir_decref(the_v2_networkstatus);
cached_dir_decref(cached_directory);
clear_cached_dir(&cached_runningrouters);
if (cached_v2_networkstatus) {
digestmap_free(cached_v2_networkstatus, _free_cached_dir);
cached_v2_networkstatus = NULL;
}
if (cached_consensuses) {
strmap_free(cached_consensuses, _free_cached_dir);
cached_consensuses = NULL;
}
}
......@@ -2062,11 +2062,10 @@ dirvote_clear_pending_consensuses(void)
for (i = 0; i < N_CONSENSUS_FLAVORS; ++i) {
pending_consensus_t *pc = &pending_consensuses[i];
tor_free(pc->body);
if (pc->consensus) {
networkstatus_vote_free(pc->consensus);
pc->consensus = NULL;
}
}
}
/** Drop all currently pending votes, consensus, and detached signatures. */
......@@ -2267,7 +2266,6 @@ dirvote_add_vote(const char *vote_body, const char **msg_out, int *status_out)
*status_out = 400;
discard:
if (vote)
networkstatus_vote_free(vote);
if (end_of_vote && !strcmpstart(end_of_vote, "network-status-version ")) {
......@@ -2453,7 +2451,6 @@ dirvote_compute_consensuses(void)
return 0;
err:
if (votes)
smartlist_free(votes);
tor_free(consensus_body);
tor_free(signatures);
......@@ -2582,7 +2579,6 @@ dirvote_add_signatures_to_all_pending_consensuses(
if (!*msg_out)
*msg_out = "Unrecognized error while adding detached signatures.";
done:
if (sigs)
ns_detached_signatures_free(sigs);
/* XXXX NM Check how return is used. We can now have an error *and*
signatures added. */
......
......@@ -366,7 +366,6 @@ dns_free_all(void)
_free_cached_resolve(item);
}
HT_CLEAR(cache_map, &cache_root);
if (cached_resolve_pqueue)
smartlist_free(cached_resolve_pqueue);
cached_resolve_pqueue = NULL;
tor_free(resolv_conf_fname);
......@@ -1644,10 +1643,9 @@ dns_seems_to_be_broken(void)
void
dns_reset_correctness_checks(void)
{
if (dns_wildcard_response_count) {
strmap_free(dns_wildcard_response_count, _tor_free);
dns_wildcard_response_count = NULL;
}
n_wildcard_requests = 0;
if (dns_wildcard_list) {
......
......@@ -1162,7 +1162,7 @@ clear_geoip_db(void)
SMARTLIST_FOREACH(geoip_countries, geoip_country_t *, c, tor_free(c));
smartlist_free(geoip_countries);
}
if (country_idxplus1_by_lc_code)
strmap_free(country_idxplus1_by_lc_code, NULL);
if (geoip_entries) {
SMARTLIST_FOREACH(geoip_entries, geoip_entry_t *, ent, tor_free(ent));
......
......@@ -1997,11 +1997,9 @@ tor_free_all(int postfork)
tor_tls_free_all();
}
/* stuff in main.c */
if (connection_array)
smartlist_free(connection_array);
if (closeable_connection_lst)
smartlist_free(closeable_connection_lst);
if (active_linked_connection_lst)
smartlist_free(active_linked_connection_lst);
tor_free(timeout_event);
if (!postfork) {
......
......@@ -337,6 +337,8 @@ microdesc_cache_rebuild(microdesc_cache_t *cache)
void
microdesc_free(microdesc_t *md)
{
if (!md)
return;
/* Must be removed from hash table! */
if (md->onion_pkey)
crypto_free_pk_env(md->onion_pkey);
......
......@@ -361,7 +361,6 @@ networkstatus_vote_free(networkstatus_t *ns)
} SMARTLIST_FOREACH_END(voter);
smartlist_free(ns->voters);
}
if (ns->cert)
authority_cert_free(ns->cert);
if (ns->routerstatus_list) {
......@@ -375,7 +374,7 @@ networkstatus_vote_free(networkstatus_t *ns)
smartlist_free(ns->routerstatus_list);
}
if (ns->desc_digest_map)
digestmap_free(ns->desc_digest_map, NULL);
memset(ns, 11, sizeof(*ns));
......@@ -1592,7 +1591,6 @@ networkstatus_set_current_consensus(const char *consensus,
if (!current_valid_after ||
c->valid_after > current_valid_after) {
waiting = &consensus_waiting_for_certs[flav];
if (waiting->consensus)
networkstatus_vote_free(waiting->consensus);
tor_free(waiting->body);
waiting->consensus = c;
......@@ -1705,7 +1703,6 @@ networkstatus_set_current_consensus(const char *consensus,
result = 0;
done:
if (c)
networkstatus_vote_free(c);
tor_free(consensus_fname);
tor_free(unverified_fname);
......@@ -1838,10 +1835,8 @@ routerstatus_list_update_named_server_map(void)
if (!current_consensus)
return;
if (named_server_map)
strmap_free(named_server_map, _tor_free);
named_server_map = strmap_new();
if (unnamed_server_map)
strmap_free(unnamed_server_map, NULL);
unnamed_server_map = strmap_new();
SMARTLIST_FOREACH(current_consensus->routerstatus_list, routerstatus_t *, rs,
......@@ -2159,14 +2154,12 @@ networkstatus_free_all(void)
smartlist_free(networkstatus_v2_list);
networkstatus_v2_list = NULL;
}
if (v2_download_status_map) {
digestmap_free(v2_download_status_map, _tor_free);
v2_download_status_map = NULL;
}
if (current_consensus) {
networkstatus_vote_free(current_consensus);
current_consensus = NULL;
}
for (i=0; i < N_CONSENSUS_FLAVORS; ++i) {
consensus_waiting_for_certs_t *waiting = &consensus_waiting_for_certs[i];
if (waiting->consensus) {
......@@ -2175,11 +2168,8 @@ networkstatus_free_all(void)
}
tor_free(waiting->body);
}
if (named_server_map) {
strmap_free(named_server_map, _tor_free);
}
if (unnamed_server_map) {
strmap_free(unnamed_server_map, NULL);
}
}
......@@ -876,7 +876,6 @@ rend_parse_service_authorization(or_options_t *options, int validate_only)
err:
res = -1;
done:
if (auth)
rend_service_authorization_free(auth);
SMARTLIST_FOREACH(sl, char *, c, tor_free(c););
smartlist_free(sl);
......
......@@ -405,7 +405,6 @@ rend_desc_v2_is_parsable(rend_encoded_v2_service_descriptor_t *desc)
&test_intro_size,
&test_encoded_size,
&test_next, desc->desc_str);
if (test_parsed)
rend_service_descriptor_free(test_parsed);
tor_free(test_intro_content);
return (res >= 0);
......@@ -428,9 +427,8 @@ rend_intro_point_free(rend_intro_point_t *intro)
{
if (!intro)
return;
if (intro->extend_info)
extend_info_free(intro->extend_info);
if (intro->intro_key)
crypto_free_pk_env(intro->intro_key);
tor_free(intro);
}
......@@ -797,9 +795,7 @@ _rend_cache_entry_free(void *p)
void
rend_cache_free_all(void)
{
if (rend_cache)
strmap_free(rend_cache, _rend_cache_entry_free);
if (rend_cache_v2_dir)
digestmap_free(rend_cache_v2_dir, _rend_cache_entry_free);
rend_cache = NULL;
rend_cache_v2_dir = NULL;
......@@ -1348,7 +1344,6 @@ rend_cache_store_v2_desc_as_client(const char *desc,
return 1;
err:
if (parsed)
rend_service_descriptor_free(parsed);
tor_free(intro_content);
return retval;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment