]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
*_free functions now accept NULL
authorSebastian Hahn <sebastian@torproject.org>
Mon, 28 Sep 2009 14:37:01 +0000 (16:37 +0200)
committerSebastian Hahn <sebastian@torproject.org>
Sat, 12 Dec 2009 02:29:44 +0000 (03:29 +0100)
Some *_free functions threw asserts when passed NULL. Now all of them
accept NULL as input and perform no action when called that way.

This gains us consistence for our free functions, and allows some
code simplifications where an explicit null check is no longer necessary.

26 files changed:
src/common/aes.c
src/common/compat.c
src/common/container.c
src/common/crypto.c
src/common/log.c
src/common/memarea.c
src/common/torgzip.c
src/common/tortls.c
src/or/buffers.c
src/or/circuitbuild.c
src/or/circuitlist.c
src/or/config.c
src/or/connection.c
src/or/connection_edge.c
src/or/connection_or.c
src/or/dirserv.c
src/or/dirvote.c
src/or/dns.c
src/or/networkstatus.c
src/or/policies.c
src/or/relay.c
src/or/rendcommon.c
src/or/rendservice.c
src/or/rephist.c
src/or/routerlist.c
src/or/routerparse.c

index e07665635b9894e0b78dd37910cfc42bbc720618..451c31f02a3bb744eab0df7a6e98592bed9166da 100644 (file)
@@ -263,7 +263,8 @@ aes_set_key(aes_cnt_cipher_t *cipher, const char *key, int key_bits)
 void
 aes_free_cipher(aes_cnt_cipher_t *cipher)
 {
-  tor_assert(cipher);
+  if (!cipher)
+    return;
 #ifdef USE_OPENSSL_EVP
   EVP_CIPHER_CTX_cleanup(&cipher->key);
 #endif
index dbd3197a88eeb7b9430cc9305de8c93116114bc6..87dedc5b571d9eab5f96d742eb0eff2b840e96ba 100644 (file)
@@ -2044,6 +2044,8 @@ tor_mutex_new(void)
 void
 tor_mutex_free(tor_mutex_t *m)
 {
+  if (!m)
+    return;
   tor_mutex_uninit(m);
   tor_free(m);
 }
@@ -2071,7 +2073,8 @@ tor_cond_new(void)
 void
 tor_cond_free(tor_cond_t *cond)
 {
-  tor_assert(cond);
+  if (!cond)
+    return;
   if (pthread_cond_destroy(&cond->cond)) {
     log_warn(LD_GENERAL,"Error freeing condition: %s", strerror(errno));
     return;
@@ -2128,7 +2131,8 @@ tor_cond_new(void)
 void
 tor_cond_free(tor_cond_t *cond)
 {
-  tor_assert(cond);
+  if (!cond)
+    return;
   DeleteCriticalSection(&cond->mutex);
   /* XXXX notify? */
   smartlist_free(cond->events);
index f3540f74d8c6e5992b901b5e064ebbbe940c11d7..7690b4c0ba845638d1d623a4b34591d083752e7a 100644 (file)
@@ -44,7 +44,8 @@ smartlist_create(void)
 void
 smartlist_free(smartlist_t *sl)
 {
-  tor_assert(sl != NULL);
+  if (!sl)
+    return;
   tor_free(sl->list);
   tor_free(sl);
 }
@@ -1187,6 +1188,9 @@ void
 strmap_free(strmap_t *map, void (*free_val)(void*))
 {
   strmap_entry_t **ent, **next, *this;
+  if (!map)
+    return;
+
   for (ent = HT_START(strmap_impl, &map->head); ent != NULL; ent = next) {
     this = *ent;
     next = HT_NEXT_RMV(strmap_impl, &map->head, ent);
@@ -1208,6 +1212,8 @@ void
 digestmap_free(digestmap_t *map, void (*free_val)(void*))
 {
   digestmap_entry_t **ent, **next, *this;
+  if (!map)
+    return;
   for (ent = HT_START(digestmap_impl, &map->head); ent != NULL; ent = next) {
     this = *ent;
     next = HT_NEXT_RMV(digestmap_impl, &map->head, ent);
@@ -1323,6 +1329,8 @@ digestset_new(int max_elements)
 void
 digestset_free(digestset_t *set)
 {
+  if (!set)
+    return;
   bitarray_free(set->ba);
   tor_free(set);
 }
index 4c880f6b6f4c1bd6a9d3d402ad9555d9eb54ce9e..4d17a8f2163f305666bf0b57c351c594d4b3e3f0 100644 (file)
@@ -400,7 +400,8 @@ crypto_new_pk_env(void)
 void
 crypto_free_pk_env(crypto_pk_env_t *env)
 {
-  tor_assert(env);
+  if (!env)
+    return;
 
   if (--env->refs > 0)
     return;
@@ -463,7 +464,8 @@ crypto_new_cipher_env(void)
 void
 crypto_free_cipher_env(crypto_cipher_env_t *env)
 {
-  tor_assert(env);
+  if (!env)
+    return;
 
   tor_assert(env->cipher);
   aes_free_cipher(env->cipher);
@@ -1528,6 +1530,8 @@ crypto_new_digest256_env(digest_algorithm_t algorithm)
 void
 crypto_free_digest_env(crypto_digest_env_t *digest)
 {
+  if (!digest)
+    return;
   memset(digest, 0, sizeof(crypto_digest_env_t));
   tor_free(digest);
 }
@@ -1899,7 +1903,8 @@ crypto_expand_key_material(const char *key_in, size_t key_in_len,
 void
 crypto_dh_free(crypto_dh_env_t *dh)
 {
-  tor_assert(dh);
+  if (!dh)
+    return;
   tor_assert(dh->dh);
   DH_free(dh->dh);
   tor_free(dh);
index 9912080af62be5935f1deb6bd40d231baf160dc8..5b5b9e086d7356c973dc0c545da5067627024b4f 100644 (file)
@@ -426,6 +426,8 @@ _log_err(log_domain_mask_t domain, const char *format, ...)
 static void
 log_free(logfile_t *victim)
 {
+  if (!victim)
+    return;
   tor_free(victim->severities);
   tor_free(victim->filename);
   tor_free(victim);
index e7f6720646856f2f262c1676784f9b0d4c141390..661bd85da889361214e966c5b5b3466e1a42d57b 100644 (file)
@@ -121,7 +121,7 @@ alloc_chunk(size_t sz, int freelist_ok)
 /** Release <b>chunk</b> from a memarea, either by adding it to the freelist
  * or by freeing it if the freelist is already too big. */
 static void
-chunk_free(memarea_chunk_t *chunk)
+chunk_free_unchecked(memarea_chunk_t *chunk)
 {
   CHECK_SENTINEL(chunk);
   if (freelist_len < MAX_FREELIST_LEN) {
@@ -151,7 +151,7 @@ memarea_drop_all(memarea_t *area)
   memarea_chunk_t *chunk, *next;
   for (chunk = area->first; chunk; chunk = next) {
     next = chunk->next_chunk;
-    chunk_free(chunk);
+    chunk_free_unchecked(chunk);
   }
   area->first = NULL; /*fail fast on */
   tor_free(area);
@@ -167,7 +167,7 @@ memarea_clear(memarea_t *area)
   if (area->first->next_chunk) {
     for (chunk = area->first->next_chunk; chunk; chunk = next) {
       next = chunk->next_chunk;
-      chunk_free(chunk);
+      chunk_free_unchecked(chunk);
     }
     area->first->next_chunk = NULL;
   }
index 762f2e71bf04628986e8fdb19a316202b72ed2da..13e0c7fb7cbc0cc57b730038412cc557d5b75cc2 100644 (file)
@@ -423,7 +423,8 @@ tor_zlib_process(tor_zlib_state_t *state,
 void
 tor_zlib_free(tor_zlib_state_t *state)
 {
-  tor_assert(state);
+  if (!state)
+    return;
 
   if (state->compress)
     deflateEnd(&state->stream);
index 71d0bd6be2647a9749f9ad39807c43cd68c7a014..0fde6177174d3863803cc9f317a0adf892973c3c 100644 (file)
@@ -986,7 +986,9 @@ void
 tor_tls_free(tor_tls_t *tls)
 {
   tor_tls_t *removed;
-  tor_assert(tls && tls->ssl);
+  if (!tls)
+    return;
+  tor_assert(tls->ssl);
   removed = HT_REMOVE(tlsmap, &tlsmap_root, tls);
   if (!removed) {
     log_warn(LD_BUG, "Freeing a TLS that was not in the ssl->tls map.");
index 1a1b2077cc6d0e8b1b1cc40c0c3b984da339cf09..7c40e47cca591c575657aeaf6bb8a9a2f797c85e 100644 (file)
@@ -147,10 +147,13 @@ get_freelist(size_t alloc)
 
 /** Deallocate a chunk or put it on a freelist */
 static void
-chunk_free(chunk_t *chunk)
+chunk_free_unchecked(chunk_t *chunk)
 {
-  size_t alloc = CHUNK_ALLOC_SIZE(chunk->memlen);
-  chunk_freelist_t *freelist = get_freelist(alloc);
+  size_t alloc;
+  chunk_freelist_t *freelist;
+
+  alloc = CHUNK_ALLOC_SIZE(chunk->memlen);
+  freelist = get_freelist(alloc);
   if (freelist && freelist->cur_length < freelist->max_length) {
     chunk->next = freelist->head;
     freelist->head = chunk;
@@ -195,7 +198,7 @@ chunk_new_with_alloc_size(size_t alloc)
 }
 #else
 static void
-chunk_free(chunk_t *chunk)
+chunk_free_unchecked(chunk_t *chunk)
 {
   tor_free(chunk);
 }
@@ -403,7 +406,7 @@ buf_pullup(buf_t *buf, size_t bytes, int nulterminate)
       dest->next = src->next;
       if (buf->tail == src)
         buf->tail = dest;
-      chunk_free(src);
+      chunk_free_unchecked(src);
     } else {
       memcpy(CHUNK_WRITE_PTR(dest), src->data, n);
       dest->datalen += n;
@@ -449,7 +452,7 @@ buf_remove_from_front(buf_t *buf, size_t n)
       buf->head = victim->next;
       if (buf->tail == victim)
         buf->tail = NULL;
-      chunk_free(victim);
+      chunk_free_unchecked(victim);
     }
   }
   check();
@@ -483,7 +486,7 @@ buf_clear(buf_t *buf)
   buf->datalen = 0;
   for (chunk = buf->head; chunk; chunk = next) {
     next = chunk->next;
-    chunk_free(chunk);
+    chunk_free_unchecked(chunk);
   }
   buf->head = buf->tail = NULL;
 }
@@ -522,6 +525,8 @@ buf_slack(const buf_t *buf)
 void
 buf_free(buf_t *buf)
 {
+  if (!buf)
+    return;
   buf_clear(buf);
   buf->magic = 0xdeadbeef;
   tor_free(buf);
index 91fa9d8db57d65d250866a78019ae2dd221ccf98..29f9d7732d0f1bae290d5f27219972d6686b0720 100644 (file)
@@ -2744,7 +2744,8 @@ extend_info_from_router(routerinfo_t *r)
 void
 extend_info_free(extend_info_t *info)
 {
-  tor_assert(info);
+  if (!info)
+    return;
   if (info->onion_key)
     crypto_free_pk_env(info->onion_key);
   tor_free(info);
@@ -3053,7 +3054,8 @@ pick_entry_guards(void)
 static void
 entry_guard_free(entry_guard_t *e)
 {
-  tor_assert(e);
+  if (!e)
+    return;
   tor_free(e->chosen_by_version);
   tor_free(e);
 }
index 02bf925ba5e9545d3c2c8b251c6477df5cc3755b..e0cb644864485989ec129efaf10e3c594fa81538 100644 (file)
@@ -442,7 +442,9 @@ circuit_free(circuit_t *circ)
 {
   void *mem;
   size_t memlen;
-  tor_assert(circ);
+  if (!circ)
+    return;
+
   if (CIRCUIT_IS_ORIGIN(circ)) {
     origin_circuit_t *ocirc = TO_ORIGIN_CIRCUIT(circ);
     mem = ocirc;
@@ -558,6 +560,9 @@ circuit_free_all(void)
 static void
 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)
index 66f9d0488bf014914921496f23d88085dace30ab..6ab87ab420edf42711cef7e43730add57007b43b 100644 (file)
@@ -859,6 +859,9 @@ get_version(void)
 static void
 or_options_free(or_options_t *options)
 {
+  if (!options)
+    return;
+
   if (options->_ExcludeExitNodesUnion)
     routerset_free(options->_ExcludeExitNodesUnion);
   config_free(&options_format, options);
@@ -2609,7 +2612,10 @@ config_free(config_format_t *fmt, void *options)
 {
   int i;
 
-  tor_assert(options);
+  if (!options)
+    return;
+
+  tor_assert(fmt);
 
   for (i=0; fmt->vars[i].name; ++i)
     option_clear(fmt, options, &(fmt->vars[i]));
index 0600d9711f5f470ff925256e5ed70513cfa06e83..ddcf08c1600ee875840b6a9f3b79fa45ea78be8b 100644 (file)
@@ -311,6 +311,9 @@ _connection_free(connection_t *conn)
 {
   void *mem;
   size_t memlen;
+  if (!conn)
+    return;
+
   switch (conn->type) {
     case CONN_TYPE_OR:
       tor_assert(conn->magic == OR_CONNECTION_MAGIC);
@@ -432,7 +435,8 @@ _connection_free(connection_t *conn)
 void
 connection_free(connection_t *conn)
 {
-  tor_assert(conn);
+  if (!conn)
+    return;
   tor_assert(!connection_is_on_closeable_list(conn));
   tor_assert(!connection_in_array(conn));
   if (conn->linked_conn) {
index 75a57fedd51bb3197b99ed25cc07535c10cc288a..b0ba96164e91f829619aa9756220dd61500f1e45 100644 (file)
@@ -688,7 +688,11 @@ addressmap_init(void)
 static void
 addressmap_ent_free(void *_ent)
 {
-  addressmap_entry_t *ent = _ent;
+  addressmap_entry_t *ent;
+  if (!_ent)
+    return;
+
+  ent = _ent;
   tor_free(ent->new_address);
   tor_free(ent);
 }
@@ -697,7 +701,11 @@ addressmap_ent_free(void *_ent)
 static void
 addressmap_virtaddress_ent_free(void *_ent)
 {
-  virtaddress_entry_t *ent = _ent;
+  virtaddress_entry_t *ent;
+  if (!_ent)
+    return;
+
+  ent = _ent;
   tor_free(ent->ipv4_address);
   tor_free(ent->hostname_address);
   tor_free(ent);
index bbd64393c3b754a773622bef390af94a9043e6bd..2ed6add9948dbba6f7d6d40e30777ed54bd3d275 100644 (file)
@@ -1075,7 +1075,8 @@ connection_init_or_handshake_state(or_connection_t *conn, int started_here)
 void
 or_handshake_state_free(or_handshake_state_t *state)
 {
-  tor_assert(state);
+  if (!state)
+    return;
   memset(state, 0xBE, sizeof(or_handshake_state_t));
   tor_free(state);
 }
index 3700cd134ed37971f8cc9307655d02e117b0d2ff..3338cd75279ea483ccb10d57b5cde0dc70321f1b 100644 (file)
@@ -1292,7 +1292,11 @@ clear_cached_dir(cached_dir_t *d)
 static void
 _free_cached_dir(void *_d)
 {
-  cached_dir_t *d = (cached_dir_t *)_d;
+  cached_dir_t *d;
+  if (!_d)
+    return;
+
+  d = (cached_dir_t *)_d;
   cached_dir_decref(d);
 }
 
index f745db6fc4ddf23db9ab20eb161bbc20dbece837..b4f76b384f65fdefb470e35018d0f2117b4ffbcf 100644 (file)
@@ -1697,6 +1697,8 @@ get_detached_signatures_from_pending_consensuses(pending_consensus_t *pending,
 void
 ns_detached_signatures_free(ns_detached_signatures_t *s)
 {
+  if (!s)
+    return;
   if (s->signatures) {
     STRMAP_FOREACH(s->signatures, flavor, smartlist_t *, sigs) {
       SMARTLIST_FOREACH(sigs, document_signature_t *, sig,
index ffd30c89d800a801a5d914666f2b39f1bbb8c1f9..8951780931a0d50e3435707c80b0a04f25a65892 100644 (file)
@@ -301,6 +301,8 @@ dns_get_expiry_ttl(uint32_t ttl)
 static void
 _free_cached_resolve(cached_resolve_t *r)
 {
+  if (!r)
+    return;
   while (r->pending_connections) {
     pending_connection_t *victim = r->pending_connections;
     r->pending_connections = victim->next;
index e9e86630620c7c7912abb833751a5795c6c6ad1c..c8bb03357f6532a85ecc442dde67774d5b761f5c 100644 (file)
@@ -266,6 +266,8 @@ static void
 vote_routerstatus_free(vote_routerstatus_t *rs)
 {
   vote_microdesc_hash_t *h, *next;
+  if (!rs)
+    return;
   tor_free(rs->version);
   tor_free(rs->status.exitsummary);
   for (h = rs->microdesc; h; h = next) {
@@ -280,6 +282,8 @@ vote_routerstatus_free(vote_routerstatus_t *rs)
 void
 routerstatus_free(routerstatus_t *rs)
 {
+  if (!rs)
+    return;
   tor_free(rs->exitsummary);
   tor_free(rs);
 }
@@ -288,6 +292,8 @@ routerstatus_free(routerstatus_t *rs)
 void
 networkstatus_v2_free(networkstatus_v2_t *ns)
 {
+  if (!ns)
+    return;
   tor_free(ns->source_address);
   tor_free(ns->contact);
   if (ns->signing_key)
index 023cd472f2b280b9b78274224e0a0112822a1919..a852ce192b5c854d6a00576994852348056ec87a 100644 (file)
@@ -1276,7 +1276,8 @@ getinfo_helper_policies(control_connection_t *conn,
 void
 addr_policy_list_free(smartlist_t *lst)
 {
-  if (!lst) return;
+  if (!lst)
+    return;
   SMARTLIST_FOREACH(lst, addr_policy_t *, policy, addr_policy_free(policy));
   smartlist_free(lst);
 }
@@ -1285,19 +1286,20 @@ addr_policy_list_free(smartlist_t *lst)
 void
 addr_policy_free(addr_policy_t *p)
 {
-  if (p) {
-    if (--p->refcnt <= 0) {
-      if (p->is_canonical) {
-        policy_map_ent_t search, *found;
-        search.policy = p;
-        found = HT_REMOVE(policy_map, &policy_root, &search);
-        if (found) {
-          tor_assert(p == found->policy);
-          tor_free(found);
-        }
+  if (!p)
+    return;
+
+  if (--p->refcnt <= 0) {
+    if (p->is_canonical) {
+      policy_map_ent_t search, *found;
+      search.policy = p;
+      found = HT_REMOVE(policy_map, &policy_root, &search);
+      if (found) {
+        tor_assert(p == found->policy);
+        tor_free(found);
       }
-      tor_free(p);
     }
+    tor_free(p);
   }
 }
 
index 00e70d95c1729085997f3bf076af8d01a032687c..ac305ce3df80bea911ecdda58e0d8febc2605bef 100644 (file)
@@ -1563,7 +1563,7 @@ clean_cell_pool(void)
 
 /** Release storage held by <b>cell</b>. */
 static INLINE void
-packed_cell_free(packed_cell_t *cell)
+packed_cell_free_unchecked(packed_cell_t *cell)
 {
   --total_cells_allocated;
   mp_pool_release(cell);
@@ -1667,7 +1667,7 @@ cell_queue_clear(cell_queue_t *queue)
   cell = queue->head;
   while (cell) {
     next = cell->next;
-    packed_cell_free(cell);
+    packed_cell_free_unchecked(cell);
     cell = next;
   }
   queue->head = queue->tail = NULL;
@@ -1913,7 +1913,7 @@ connection_or_flush_from_first_active_circuit(or_connection_t *conn, int max,
 
     connection_write_to_buf(cell->body, CELL_NETWORK_SIZE, TO_CONN(conn));
 
-    packed_cell_free(cell);
+    packed_cell_free_unchecked(cell);
     ++n_flushed;
     if (circ != conn->active_circuits) {
       /* If this happens, the current circuit just got made inactive by
index 9055f981bb53900519562f820a8f26fa7b40db72..a68ee0c501ca94021d30f6db3eccff36202bb545 100644 (file)
@@ -22,6 +22,8 @@ rend_cmp_service_ids(const char *one, const char *two)
 void
 rend_service_descriptor_free(rend_service_descriptor_t *desc)
 {
+  if (!desc)
+    return;
   if (desc->pk)
     crypto_free_pk_env(desc->pk);
   if (desc->intro_nodes) {
@@ -414,6 +416,8 @@ void
 rend_encoded_v2_service_descriptor_free(
   rend_encoded_v2_service_descriptor_t *desc)
 {
+  if (!desc)
+    return;
   tor_free(desc->desc_str);
   tor_free(desc);
 }
@@ -422,6 +426,8 @@ rend_encoded_v2_service_descriptor_free(
 void
 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)
index b6981d6258f7154f474b97d947a554e2235874eb..445fbffb042965804abed25cc0059173f1f631ee 100644 (file)
@@ -87,7 +87,8 @@ num_rend_services(void)
 static void
 rend_authorized_client_free(rend_authorized_client_t *client)
 {
-  if (!client) return;
+  if (!client)
+    return;
   if (client->client_key)
     crypto_free_pk_env(client->client_key);
   tor_free(client->client_name);
@@ -106,7 +107,9 @@ rend_authorized_client_strmap_item_free(void *authorized_client)
 static void
 rend_service_free(rend_service_t *service)
 {
-  if (!service) return;
+  if (!service)
+    return;
+
   tor_free(service->directory);
   SMARTLIST_FOREACH(service->ports, void*, p, tor_free(p));
   smartlist_free(service->ports);
@@ -134,9 +137,9 @@ rend_service_free(rend_service_t *service)
 void
 rend_service_free_all(void)
 {
-  if (!rend_service_list) {
+  if (!rend_service_list)
     return;
-  }
+
   SMARTLIST_FOREACH(rend_service_list, rend_service_t*, ptr,
                     rend_service_free(ptr));
   smartlist_free(rend_service_list);
index 1ff9cde69fb706ca1073e7b0c04fe87e9f27ef2d..78ceb5f0d7aa52a602d39edad0b1b49308feedd4 100644 (file)
@@ -2272,6 +2272,8 @@ static void
 hs_usage_general_period_related_observations_free(
                              hs_usage_general_period_related_observations_t *s)
 {
+  if (!s)
+    return;
   rephist_total_alloc-=sizeof(hs_usage_general_period_related_observations_t);
   tor_free(s);
 }
@@ -2281,6 +2283,8 @@ static void
 hs_usage_current_observation_period_free(
                                     hs_usage_current_observation_period_t *s)
 {
+  if (!s)
+    return;
   rephist_total_alloc -= sizeof(hs_usage_current_observation_period_t);
   tor_free(s);
 }
index 18d656d222ba1408d4e7acb69ad6e9f8ecf69bbf..3484338e505542de3e2847483210a64a37db5c29 100644 (file)
@@ -2378,6 +2378,9 @@ extrainfo_free(extrainfo_t *extrainfo)
 static void
 signed_descriptor_free(signed_descriptor_t *sd)
 {
+  if (!sd)
+    return;
+
   tor_free(sd->signed_descriptor_body);
 
   /* XXXX remove this once more bugs go away. */
@@ -2409,7 +2412,8 @@ _extrainfo_free(void *e)
 void
 routerlist_free(routerlist_t *rl)
 {
-  tor_assert(rl);
+  if (!rl)
+    return;
   rimap_free(rl->identity_map, NULL);
   sdmap_free(rl->desc_digest_map, NULL);
   sdmap_free(rl->desc_by_eid_map, NULL);
@@ -3779,6 +3783,9 @@ authority_cert_free(authority_cert_t *cert)
 static void
 trusted_dir_server_free(trusted_dir_server_t *ds)
 {
+  if (!ds)
+    return;
+
   tor_free(ds->nickname);
   tor_free(ds->description);
   tor_free(ds->address);
@@ -5305,6 +5312,9 @@ routerset_equal(const routerset_t *old, const routerset_t *new)
 void
 routerset_free(routerset_t *routerset)
 {
+  if (!routerset)
+    return;
+
   SMARTLIST_FOREACH(routerset->list, char *, cp, tor_free(cp));
   smartlist_free(routerset->list);
   SMARTLIST_FOREACH(routerset->policies, addr_policy_t *, p,
index 1f89cffa018790990b339f2e684a8c30f1898e54..864056f44f3e4c35150e651ee717605cee9d8c78 100644 (file)
@@ -151,7 +151,7 @@ typedef enum {
  * type.
  *
  * This structure is only allocated in memareas; do not allocate it on
- * the heap, or token_free() won't work.
+ * the heap, or token_clear() won't work.
  */
 typedef struct directory_token_t {
   directory_keyword tp;        /**< Type of the token. */
@@ -523,7 +523,7 @@ static int router_get_hash_impl(const char *s, char *digest,
 static int router_get_hashes_impl(const char *s, digests_t *digests,
                                   const char *start_str, const char *end_str,
                                   char end_char);
-static void token_free(directory_token_t *tok);
+static void token_clear(directory_token_t *tok);
 static smartlist_t *find_all_exitpolicy(smartlist_t *s);
 static directory_token_t *_find_by_keyword(smartlist_t *s,
                                            directory_keyword keyword,
@@ -844,7 +844,7 @@ router_parse_directory(const char *str)
                             CST_CHECK_AUTHORITY, "directory")<0)
     goto err;
 
-  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
+  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
   smartlist_clear(tokens);
   memarea_clear(area);
 
@@ -882,7 +882,7 @@ router_parse_directory(const char *str)
  done:
   if (declared_key) crypto_free_pk_env(declared_key);
   if (tokens) {
-    SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
+    SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
     smartlist_free(tokens);
   }
   if (area) {
@@ -948,7 +948,7 @@ router_parse_runningrouters(const char *str)
   dump_desc(str_dup, "v1 running-routers");
   if (declared_key) crypto_free_pk_env(declared_key);
   if (tokens) {
-    SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
+    SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
     smartlist_free(tokens);
   }
   if (area) {
@@ -998,7 +998,7 @@ find_dir_signing_key(const char *str, const char *eos)
   }
 
  done:
-  if (tok) token_free(tok);
+  if (tok) token_clear(tok);
   if (area) {
     DUMP_AREA(area, "dir-signing-key token");
     memarea_drop_all(area);
@@ -1551,7 +1551,7 @@ router_parse_entry_from_string(const char *s, const char *end,
   router = NULL;
  done:
   if (tokens) {
-    SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
+    SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
     smartlist_free(tokens);
   }
   if (exit_policy_tokens) {
@@ -1677,7 +1677,7 @@ extrainfo_parse_entry_from_string(const char *s, const char *end,
   extrainfo = NULL;
  done:
   if (tokens) {
-    SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
+    SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
     smartlist_free(tokens);
   }
   if (area) {
@@ -1848,7 +1848,7 @@ authority_cert_parse_from_string(const char *s, const char **end_of_string)
   if (end_of_string) {
     *end_of_string = eat_whitespace(eos);
   }
-  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
+  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
   smartlist_free(tokens);
   if (area) {
     DUMP_AREA(area, "authority cert");
@@ -1858,7 +1858,7 @@ authority_cert_parse_from_string(const char *s, const char **end_of_string)
  err:
   dump_desc(s_dup, "authority cert");
   authority_cert_free(cert);
-  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
+  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
   smartlist_free(tokens);
   if (area) {
     DUMP_AREA(area, "authority cert");
@@ -2129,7 +2129,7 @@ routerstatus_parse_entry_from_string(memarea_t *area,
     routerstatus_free(rs);
   rs = NULL;
  done:
-  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
+  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
   smartlist_clear(tokens);
   if (area) {
     DUMP_AREA(area, "routerstatus entry");
@@ -2280,7 +2280,7 @@ networkstatus_v2_parse_from_string(const char *s)
 
   ns->entries = smartlist_create();
   s = eos;
-  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
+  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
   smartlist_clear(tokens);
   memarea_clear(area);
   while (!strcmpstart(s, "r ")) {
@@ -2320,9 +2320,9 @@ networkstatus_v2_parse_from_string(const char *s)
     networkstatus_v2_free(ns);
   ns = NULL;
  done:
-  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
+  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
   smartlist_free(tokens);
-  SMARTLIST_FOREACH(footer_tokens, directory_token_t *, t, token_free(t));
+  SMARTLIST_FOREACH(footer_tokens, directory_token_t *, t, token_clear(t));
   smartlist_free(footer_tokens);
   if (area) {
     DUMP_AREA(area, "v2 networkstatus");
@@ -2799,7 +2799,7 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out,
   ns = NULL;
  done:
   if (tokens) {
-    SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
+    SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
     smartlist_free(tokens);
   }
   if (voter) {
@@ -2814,11 +2814,11 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out,
     tor_free(voter);
   }
   if (rs_tokens) {
-    SMARTLIST_FOREACH(rs_tokens, directory_token_t *, t, token_free(t));
+    SMARTLIST_FOREACH(rs_tokens, directory_token_t *, t, token_clear(t));
     smartlist_free(rs_tokens);
   }
   if (footer_tokens) {
-    SMARTLIST_FOREACH(footer_tokens, directory_token_t *, t, token_free(t));
+    SMARTLIST_FOREACH(footer_tokens, directory_token_t *, t, token_clear(t));
     smartlist_free(footer_tokens);
   }
   if (area) {
@@ -3052,7 +3052,7 @@ networkstatus_parse_detached_signatures(const char *s, const char *eos)
   ns_detached_signatures_free(sigs);
   sigs = NULL;
  done:
-  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
+  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
   smartlist_free(tokens);
   if (area) {
     DUMP_AREA(area, "detached signatures");
@@ -3108,7 +3108,7 @@ router_parse_addr_policy_item_from_string(const char *s, int assume_action)
  err:
   r = NULL;
  done:
-  token_free(tok);
+  token_clear(tok);
   if (area) {
     DUMP_AREA(area, "policy item");
     memarea_drop_all(area);
@@ -3231,9 +3231,8 @@ assert_addr_policy_ok(smartlist_t *lst)
 
 /** Free all resources allocated for <b>tok</b> */
 static void
-token_free(directory_token_t *tok)
+token_clear(directory_token_t *tok)
 {
-  tor_assert(tok);
   if (tok->key)
     crypto_free_pk_env(tok->key);
 }
@@ -3245,7 +3244,7 @@ token_free(directory_token_t *tok)
 
 #define RET_ERR(msg)                                               \
   STMT_BEGIN                                                       \
-    if (tok) token_free(tok);                                      \
+    if (tok) token_clear(tok);                                      \
     tok = ALLOC_ZERO(sizeof(directory_token_t));                   \
     tok->tp = _ERR;                                                \
     tok->error = STRDUP(msg);                                      \
@@ -3523,7 +3522,7 @@ tokenize_string(memarea_t *area,
     tok = get_next_token(area, s, end, table);
     if (tok->tp == _ERR) {
       log_warn(LD_DIR, "parse error: %s", tok->error);
-      token_free(tok);
+      token_clear(tok);
       return -1;
     }
     ++counts[tok->tp];
@@ -4270,7 +4269,7 @@ rend_parse_v2_service_descriptor(rend_service_descriptor_t **parsed_out,
   result = NULL;
  done:
   if (tokens) {
-    SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
+    SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
     smartlist_free(tokens);
   }
   if (area)
@@ -4428,7 +4427,7 @@ rend_parse_introduction_points(rend_service_descriptor_t *parsed,
       eos = eos+1;
     tor_assert(eos <= intro_points_encoded+intro_points_encoded_size);
     /* Free tokens and clear token list. */
-    SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
+    SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
     smartlist_clear(tokens);
     memarea_clear(area);
     /* Tokenize string. */
@@ -4501,7 +4500,7 @@ rend_parse_introduction_points(rend_service_descriptor_t *parsed,
 
  done:
   /* Free tokens and clear token list. */
-  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
+  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
   smartlist_free(tokens);
   if (area)
     memarea_drop_all(area);
@@ -4540,7 +4539,7 @@ rend_parse_client_keys(strmap_t *parsed_clients, const char *ckstr)
     else
       eos = eos + 1;
     /* Free tokens and clear token list. */
-    SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
+    SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
     smartlist_clear(tokens);
     memarea_clear(area);
     /* Tokenize string. */
@@ -4612,7 +4611,7 @@ rend_parse_client_keys(strmap_t *parsed_clients, const char *ckstr)
   result = -1;
  done:
   /* Free tokens and clear token list. */
-  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
+  SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
   smartlist_free(tokens);
   if (area)
     memarea_drop_all(area);