[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] [tor/master] Now that FOO_free(NULL) always works, remove checks before calling it.



Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Sat, 12 Dec 2009 02:07:59 -0500
Subject: Now that FOO_free(NULL) always works, remove checks before calling it.
Commit: 0c1b3070cfec670190636d74f97c2aaf0e521bdb

---
 src/common/torgzip.c     |    4 +--
 src/common/tortls.c      |    6 +---
 src/common/util.c        |    3 +-
 src/or/circuitbuild.c    |   15 ++++-------
 src/or/circuitlist.c     |   50 ++++++++++++++-------------------------
 src/or/circuituse.c      |    7 ++---
 src/or/config.c          |   31 ++++++++++--------------
 src/or/connection.c      |   27 ++++++++------------
 src/or/connection_edge.c |   13 ++++------
 src/or/connection_or.c   |   15 +++++------
 src/or/control.c         |    3 +-
 src/or/dirserv.c         |   22 ++++++-----------
 src/or/dirvote.c         |   16 ++++--------
 src/or/dns.c             |   10 +++----
 src/or/geoip.c           |    4 +-
 src/or/main.c            |   10 +++----
 src/or/microdesc.c       |    2 +
 src/or/networkstatus.c   |   42 ++++++++++++--------------------
 src/or/rendclient.c      |    3 +-
 src/or/rendcommon.c      |   19 +++++---------
 src/or/rendservice.c     |   15 +++++------
 src/or/router.c          |   58 ++++++++++++++++------------------------------
 src/or/routerlist.c      |   24 +++++++------------
 src/or/routerparse.c     |   19 ++++----------
 24 files changed, 160 insertions(+), 258 deletions(-)

diff --git a/src/common/torgzip.c b/src/common/torgzip.c
index 13e0c7f..4f1b46a 100644
--- a/src/common/torgzip.c
+++ b/src/common/torgzip.c
@@ -165,9 +165,7 @@ tor_gzip_compress(char **out, size_t *out_len,
     deflateEnd(stream);
     tor_free(stream);
   }
-  if (*out) {
-    tor_free(*out);
-  }
+  tor_free(*out);
   return -1;
 }
 
diff --git a/src/common/tortls.c b/src/common/tortls.c
index 0fde617..86f07a2 100644
--- a/src/common/tortls.c
+++ b/src/common/tortls.c
@@ -1314,10 +1314,8 @@ 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);
+  tor_free(s1);
+  tor_free(s2);
 }
 
 /** Helper function: try to extract a link certificate and an identity
diff --git a/src/common/util.c b/src/common/util.c
index 989efd9..5ad12c3 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -953,8 +953,7 @@ const char *
 escaped(const char *s)
 {
   static char *_escaped_val = NULL;
-  if (_escaped_val)
-    tor_free(_escaped_val);
+  tor_free(_escaped_val);
 
   if (s)
     _escaped_val = esc_for_log(s);
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 29f9d77..de9ebe1 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -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;
-  }
+  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,8 +2429,7 @@ 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);
+  extend_info_free(state->chosen_exit);
   state->chosen_exit = extend_info_dup(exit);
 
   ++circ->build_state->desired_path_len;
@@ -2746,8 +2744,7 @@ extend_info_free(extend_info_t *info)
 {
   if (!info)
     return;
-  if (info->onion_key)
-    crypto_free_pk_env(info->onion_key);
+  crypto_free_pk_env(info->onion_key);
   tor_free(info);
 }
 
diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index e0cb644..2c949de 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -451,18 +451,15 @@ 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);
+
+    crypto_free_pk_env(ocirc->intro_key);
+    rend_data_free(ocirc->rend_data);
   } else {
     or_circuit_t *ocirc = TO_OR_CIRCUIT(circ);
     /* Remember cell statistics for this circuit before deallocating. */
@@ -472,14 +469,10 @@ 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);
+    crypto_free_cipher_env(ocirc->p_crypto);
+    crypto_free_digest_env(ocirc->p_digest);
+    crypto_free_cipher_env(ocirc->n_crypto);
+    crypto_free_digest_env(ocirc->n_digest);
 
     if (ocirc->rend_splice) {
       or_circuit_t *other = ocirc->rend_splice;
@@ -495,8 +488,7 @@ circuit_free(circuit_t *circ)
     cell_queue_clear(&ocirc->p_conn_cells);
   }
 
-  if (circ->n_hop)
-    extend_info_free(circ->n_hop);
+  extend_info_free(circ->n_hop);
   tor_free(circ->n_conn_onionskin);
 
   /* Remove from map. */
@@ -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;
-  }
+
+  smartlist_free(circuits_pending_or_conns);
+  circuits_pending_or_conns = NULL;
+
   HT_CLEAR(orconn_circid_map, &orconn_circid_circuit_map);
 }
 
@@ -563,18 +555,12 @@ 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);
+  crypto_free_cipher_env(victim->f_crypto);
+  crypto_free_cipher_env(victim->b_crypto);
+  crypto_free_digest_env(victim->f_digest);
+  crypto_free_digest_env(victim->b_digest);
+  crypto_dh_free(victim->dh_handshake_state);
+  extend_info_free(victim->extend_info);
 
   memset(victim, 0xBB, sizeof(crypt_path_t)); /* poison memory */
   tor_free(victim);
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 1022ae1..a87f674 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -928,8 +928,8 @@ 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);
+
+  extend_info_free(info);
   return circ;
 }
 
@@ -1222,8 +1222,7 @@ circuit_get_open_circ_or_launch(edge_connection_t *conn,
                                            flags);
     }
 
-    if (extend_info)
-      extend_info_free(extend_info);
+    extend_info_free(extend_info);
 
     if (desired_circuit_purpose != CIRCUIT_PURPOSE_C_GENERAL) {
       /* help predict this next time */
diff --git a/src/or/config.c b/src/or/config.c
index 6ab87ab..416cbc1 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -827,8 +827,8 @@ 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);
+
+  config_free(&options_format, old_options);
 
   return 0;
 }
@@ -862,8 +862,7 @@ or_options_free(or_options_t *options)
   if (!options)
     return;
 
-  if (options->_ExcludeExitNodesUnion)
-    routerset_free(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;
-  }
+  or_options_free(global_options);
+  global_options = NULL;
+
+  config_free(&state_format, global_state);
+  global_state = NULL;
+
+  config_free_lines(global_cmdline_options);
+  global_cmdline_options = NULL;
+
   tor_free(torrc_fname);
   tor_free(_version);
   tor_free(global_dirfrontpagecontents);
@@ -5089,8 +5085,7 @@ or_state_set(or_state_t *new_state)
 {
   char *err = NULL;
   tor_assert(new_state);
-  if (global_state)
-    config_free(&state_format, global_state);
+  config_free(&state_format, global_state);
   global_state = new_state;
   if (entry_guards_parse_state(global_state, 1, &err)<0) {
     log_warn(LD_GENERAL,"%s",err);
diff --git a/src/or/connection.c b/src/or/connection.c
index ddcf08c..0ff1cc5 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -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_tls_free(or_conn->tls);
+    or_conn->tls = NULL;
+    or_handshake_state_free(or_conn->handshake_state);
+    or_conn->handshake_state = NULL;
     tor_free(or_conn->nickname);
   }
   if (CONN_IS_EDGE(conn)) {
@@ -388,8 +384,8 @@ _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);
+
+    rend_data_free(edge_conn->rend_data);
   }
   if (conn->type == CONN_TYPE_CONTROL) {
     control_connection_t *control_conn = TO_CONTROL_CONN(conn);
@@ -402,16 +398,15 @@ _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);
+
+    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);
+
+    cached_dir_decref(dir_conn->cached_dir);
+    rend_data_free(dir_conn->rend_data);
   }
 
   if (conn->s >= 0) {
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index b0ba961..a6b3746 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -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;
-  }
+  strmap_free(addressmap, addressmap_ent_free);
+  addressmap = NULL;
+
+  strmap_free(virtaddress_reversemap, addressmap_virtaddress_ent_free);
+  virtaddress_reversemap = NULL;
 }
 
 /** Look at address, and rewrite it until it doesn't want any
diff --git a/src/or/connection_or.c b/src/or/connection_or.c
index 2ed6add..0c32eef 100644
--- a/src/or/connection_or.c
+++ b/src/or/connection_or.c
@@ -80,10 +80,9 @@ connection_or_clear_identity_map(void)
     }
   });
 
-  if (orconn_identity_map) {
-    digestmap_free(orconn_identity_map, NULL);
-    orconn_identity_map = NULL;
-  }
+
+  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;
-  }
+
+  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. */
 
diff --git a/src/or/control.c b/src/or/control.c
index 0099943..3674b0f 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -2143,8 +2143,7 @@ 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);
+  smartlist_free(routers);
   return 0;
 }
 
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 3338cd7..b7f6713 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -2818,10 +2818,8 @@ 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);
+  smartlist_free(routers);
+  digestmap_free(omit_as_sybil, NULL);
   return r;
 }
 
@@ -3497,8 +3495,7 @@ 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);
+      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;
-  }
+
+  digestmap_free(cached_v2_networkstatus, _free_cached_dir);
+  cached_v2_networkstatus = NULL;
+  strmap_free(cached_consensuses, _free_cached_dir);
+  cached_consensuses = NULL;
 }
 
diff --git a/src/or/dirvote.c b/src/or/dirvote.c
index b4f76b3..7227ac9 100644
--- a/src/or/dirvote.c
+++ b/src/or/dirvote.c
@@ -2062,10 +2062,9 @@ 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;
-    }
+
+    networkstatus_vote_free(pc->consensus);
+    pc->consensus = NULL;
   }
 }
 
@@ -2267,8 +2266,7 @@ dirvote_add_vote(const char *vote_body, const char **msg_out, int *status_out)
     *status_out = 400;
 
  discard:
-  if (vote)
-    networkstatus_vote_free(vote);
+  networkstatus_vote_free(vote);
 
   if (end_of_vote && !strcmpstart(end_of_vote, "network-status-version ")) {
     vote_body = end_of_vote;
@@ -2453,8 +2451,7 @@ dirvote_compute_consensuses(void)
 
   return 0;
  err:
-  if (votes)
-    smartlist_free(votes);
+  smartlist_free(votes);
   tor_free(consensus_body);
   tor_free(signatures);
   networkstatus_vote_free(consensus);
@@ -2582,8 +2579,7 @@ 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);
+  ns_detached_signatures_free(sigs);
   /* XXXX NM Check how return is used.  We can now have an error *and*
      signatures added. */
   return r;
diff --git a/src/or/dns.c b/src/or/dns.c
index 8951780..963039d 100644
--- a/src/or/dns.c
+++ b/src/or/dns.c
@@ -366,8 +366,7 @@ dns_free_all(void)
     _free_cached_resolve(item);
   }
   HT_CLEAR(cache_map, &cache_root);
-  if (cached_resolve_pqueue)
-    smartlist_free(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;
-  }
+  strmap_free(dns_wildcard_response_count, _tor_free);
+  dns_wildcard_response_count = NULL;
+
   n_wildcard_requests = 0;
 
   if (dns_wildcard_list) {
diff --git a/src/or/geoip.c b/src/or/geoip.c
index 5b40c2e..a57e1fb 100644
--- a/src/or/geoip.c
+++ b/src/or/geoip.c
@@ -1162,8 +1162,8 @@ 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);
+
+  strmap_free(country_idxplus1_by_lc_code, NULL);
   if (geoip_entries) {
     SMARTLIST_FOREACH(geoip_entries, geoip_entry_t *, ent, tor_free(ent));
     smartlist_free(geoip_entries);
diff --git a/src/or/main.c b/src/or/main.c
index 537abcc..8db2bbb 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -1997,12 +1997,10 @@ 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);
+
+  smartlist_free(connection_array);
+  smartlist_free(closeable_connection_lst);
+  smartlist_free(active_linked_connection_lst);
   tor_free(timeout_event);
   if (!postfork) {
     release_lockfile();
diff --git a/src/or/microdesc.c b/src/or/microdesc.c
index 7a65705..c1f447c 100644
--- a/src/or/microdesc.c
+++ b/src/or/microdesc.c
@@ -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);
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index c8bb033..f3925f1 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -361,8 +361,7 @@ networkstatus_vote_free(networkstatus_t *ns)
     } SMARTLIST_FOREACH_END(voter);
     smartlist_free(ns->voters);
   }
-  if (ns->cert)
-    authority_cert_free(ns->cert);
+  authority_cert_free(ns->cert);
 
   if (ns->routerstatus_list) {
     if (ns->type == NS_TYPE_VOTE || ns->type == NS_TYPE_OPINION) {
@@ -375,8 +374,8 @@ networkstatus_vote_free(networkstatus_t *ns)
 
     smartlist_free(ns->routerstatus_list);
   }
-  if (ns->desc_digest_map)
-    digestmap_free(ns->desc_digest_map, NULL);
+
+  digestmap_free(ns->desc_digest_map, NULL);
 
   memset(ns, 11, sizeof(*ns));
   tor_free(ns);
@@ -1592,8 +1591,7 @@ 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);
+        networkstatus_vote_free(waiting->consensus);
         tor_free(waiting->body);
         waiting->consensus = c;
         c = NULL; /* Prevent free. */
@@ -1705,8 +1703,7 @@ networkstatus_set_current_consensus(const char *consensus,
 
   result = 0;
  done:
-  if (c)
-    networkstatus_vote_free(c);
+  networkstatus_vote_free(c);
   tor_free(consensus_fname);
   tor_free(unverified_fname);
   return result;
@@ -1838,11 +1835,9 @@ routerstatus_list_update_named_server_map(void)
   if (!current_consensus)
     return;
 
-  if (named_server_map)
-    strmap_free(named_server_map, _tor_free);
+  strmap_free(named_server_map, _tor_free);
   named_server_map = strmap_new();
-  if (unnamed_server_map)
-    strmap_free(unnamed_server_map, NULL);
+  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;
-  }
+
+  digestmap_free(v2_download_status_map, _tor_free);
+  v2_download_status_map = NULL;
+  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);
-  }
+
+  strmap_free(named_server_map, _tor_free);
+  strmap_free(unnamed_server_map, NULL);
 }
 
diff --git a/src/or/rendclient.c b/src/or/rendclient.c
index b7ea40e..9268647 100644
--- a/src/or/rendclient.c
+++ b/src/or/rendclient.c
@@ -876,8 +876,7 @@ rend_parse_service_authorization(or_options_t *options, int validate_only)
  err:
   res = -1;
  done:
-  if (auth)
-    rend_service_authorization_free(auth);
+  rend_service_authorization_free(auth);
   SMARTLIST_FOREACH(sl, char *, c, tor_free(c););
   smartlist_free(sl);
   if (!validate_only && res == 0) {
diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c
index 92a9af7..6567f14 100644
--- a/src/or/rendcommon.c
+++ b/src/or/rendcommon.c
@@ -405,8 +405,7 @@ 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);
+  rend_service_descriptor_free(test_parsed);
   tor_free(test_intro_content);
   return (res >= 0);
 }
@@ -428,10 +427,9 @@ 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);
+
+  extend_info_free(intro->extend_info);
+  crypto_free_pk_env(intro->intro_key);
   tor_free(intro);
 }
 
@@ -797,10 +795,8 @@ _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);
+  strmap_free(rend_cache, _rend_cache_entry_free);
+  digestmap_free(rend_cache_v2_dir, _rend_cache_entry_free);
   rend_cache = NULL;
   rend_cache_v2_dir = NULL;
 }
@@ -1348,8 +1344,7 @@ rend_cache_store_v2_desc_as_client(const char *desc,
   return 1;
 
  err:
-  if (parsed)
-    rend_service_descriptor_free(parsed);
+  rend_service_descriptor_free(parsed);
   tor_free(intro_content);
   return retval;
 }
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index 445fbff..de3fa0f 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -120,15 +120,14 @@ rend_service_free(rend_service_t *service)
       rend_intro_point_free(intro););
     smartlist_free(service->intro_nodes);
   }
-  if (service->desc)
-    rend_service_descriptor_free(service->desc);
+
+  rend_service_descriptor_free(service->desc);
   if (service->clients) {
     SMARTLIST_FOREACH(service->clients, rend_authorized_client_t *, c,
       rend_authorized_client_free(c););
     smartlist_free(service->clients);
   }
-  if (service->accepted_intros)
-    digestmap_free(service->accepted_intros, _tor_free);
+  digestmap_free(service->accepted_intros, _tor_free);
   tor_free(service);
 }
 
@@ -485,10 +484,10 @@ rend_service_update_descriptor(rend_service_t *service)
   rend_service_descriptor_t *d;
   origin_circuit_t *circ;
   int i;
-  if (service->desc) {
-    rend_service_descriptor_free(service->desc);
-    service->desc = NULL;
-  }
+
+  rend_service_descriptor_free(service->desc);
+  service->desc = NULL;
+
   d = service->desc = tor_malloc_zero(sizeof(rend_service_descriptor_t));
   d->pk = crypto_pk_dup_key(service->private_key);
   d->timestamp = time(NULL);
diff --git a/src/or/router.c b/src/or/router.c
index 2f5a9fd..8b6d1d9 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -61,8 +61,7 @@ static void
 set_onion_key(crypto_pk_env_t *k)
 {
   tor_mutex_acquire(key_lock);
-  if (onionkey)
-    crypto_free_pk_env(onionkey);
+  crypto_free_pk_env(onionkey);
   onionkey = k;
   onionkey_set_at = time(NULL);
   tor_mutex_release(key_lock);
@@ -111,8 +110,7 @@ get_onion_key_set_at(void)
 void
 set_identity_key(crypto_pk_env_t *k)
 {
-  if (identitykey)
-    crypto_free_pk_env(identitykey);
+  crypto_free_pk_env(identitykey);
   identitykey = k;
   crypto_pk_get_digest(identitykey, identitykey_digest);
 }
@@ -201,8 +199,7 @@ rotate_onion_key(void)
   }
   log_info(LD_GENERAL, "Rotating onion key");
   tor_mutex_acquire(key_lock);
-  if (lastonionkey)
-    crypto_free_pk_env(lastonionkey);
+  crypto_free_pk_env(lastonionkey);
   lastonionkey = onionkey;
   onionkey = prkey;
   now = time(NULL);
@@ -331,10 +328,9 @@ load_authority_keyset(int legacy, crypto_pk_env_t **key_out,
     goto done;
   }
 
-  if (*key_out)
-    crypto_free_pk_env(*key_out);
-  if (*cert_out)
-    authority_cert_free(*cert_out);
+  crypto_free_pk_env(*key_out);
+  authority_cert_free(*cert_out);
+
   *key_out = signing_key;
   *cert_out = parsed;
   r = 0;
@@ -344,10 +340,8 @@ load_authority_keyset(int legacy, crypto_pk_env_t **key_out,
  done:
   tor_free(fname);
   tor_free(cert);
-  if (signing_key)
-    crypto_free_pk_env(signing_key);
-  if (parsed)
-    authority_cert_free(parsed);
+  crypto_free_pk_env(signing_key);
+  authority_cert_free(parsed);
   return r;
 }
 
@@ -1425,11 +1419,9 @@ router_rebuild_descriptor(int force)
 
   tor_assert(! routerinfo_incompatible_with_extrainfo(ri, ei, NULL, NULL));
 
-  if (desc_routerinfo)
-    routerinfo_free(desc_routerinfo);
+  routerinfo_free(desc_routerinfo);
   desc_routerinfo = ri;
-  if (desc_extrainfo)
-    extrainfo_free(desc_extrainfo);
+  extrainfo_free(desc_extrainfo);
   desc_extrainfo = ei;
 
   desc_clean_since = time(NULL);
@@ -2169,26 +2161,16 @@ router_purpose_from_string(const char *s)
 void
 router_free_all(void)
 {
-  if (onionkey)
-    crypto_free_pk_env(onionkey);
-  if (lastonionkey)
-    crypto_free_pk_env(lastonionkey);
-  if (identitykey)
-    crypto_free_pk_env(identitykey);
-  if (key_lock)
-    tor_mutex_free(key_lock);
-  if (desc_routerinfo)
-    routerinfo_free(desc_routerinfo);
-  if (desc_extrainfo)
-    extrainfo_free(desc_extrainfo);
-  if (authority_signing_key)
-    crypto_free_pk_env(authority_signing_key);
-  if (authority_key_certificate)
-    authority_cert_free(authority_key_certificate);
-  if (legacy_signing_key)
-    crypto_free_pk_env(legacy_signing_key);
-  if (legacy_key_certificate)
-    authority_cert_free(legacy_key_certificate);
+  crypto_free_pk_env(onionkey);
+  crypto_free_pk_env(lastonionkey);
+  crypto_free_pk_env(identitykey);
+  tor_mutex_free(key_lock);
+  routerinfo_free(desc_routerinfo);
+  extrainfo_free(desc_extrainfo);
+  crypto_free_pk_env(authority_signing_key);
+  authority_cert_free(authority_key_certificate);
+  crypto_free_pk_env(legacy_signing_key);
+  authority_cert_free(legacy_key_certificate);
 
   if (warned_nonexistent_family) {
     SMARTLIST_FOREACH(warned_nonexistent_family, char *, cp, tor_free(cp));
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 3484338..7275e1d 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -757,8 +757,7 @@ router_rebuild_store(int flags, desc_store_t *store)
   store->journal_len = 0;
   store->bytes_dropped = 0;
  done:
-  if (signed_descriptors)
-    smartlist_free(signed_descriptors);
+  smartlist_free(signed_descriptors);
   tor_free(fname);
   tor_free(fname_tmp);
   if (chunk_list) {
@@ -2861,8 +2860,7 @@ routerlist_reparse_old(routerlist_t *rl, signed_descriptor_t *sd)
 void
 routerlist_free_all(void)
 {
-  if (routerlist)
-    routerlist_free(routerlist);
+  routerlist_free(routerlist);
   routerlist = NULL;
   if (warned_nicknames) {
     SMARTLIST_FOREACH(warned_nicknames, char *, cp, tor_free(cp));
@@ -3771,10 +3769,8 @@ authority_cert_free(authority_cert_t *cert)
     return;
 
   tor_free(cert->cache_info.signed_descriptor_body);
-  if (cert->signing_key)
-    crypto_free_pk_env(cert->signing_key);
-  if (cert->identity_key)
-    crypto_free_pk_env(cert->identity_key);
+  crypto_free_pk_env(cert->signing_key);
+  crypto_free_pk_env(cert->identity_key);
 
   tor_free(cert);
 }
@@ -4829,8 +4825,8 @@ esc_router_info(routerinfo_t *router)
   static char *info=NULL;
   char *esc_contact, *esc_platform;
   size_t len;
-  if (info)
-    tor_free(info);
+  tor_free(info);
+
   if (!router)
     return NULL; /* we're exiting; just free the memory we use */
 
@@ -4965,9 +4961,8 @@ void
 routerset_refresh_countries(routerset_t *target)
 {
   int cc;
-  if (target->countries) {
-    bitarray_free(target->countries);
-  }
+  bitarray_free(target->countries);
+
   if (!geoip_is_loaded()) {
     target->countries = NULL;
     target->n_countries = 0;
@@ -5325,8 +5320,7 @@ routerset_free(routerset_t *routerset)
 
   strmap_free(routerset->names, NULL);
   digestmap_free(routerset->digests, NULL);
-  if (routerset->countries)
-    bitarray_free(routerset->countries);
+  bitarray_free(routerset->countries);
   tor_free(routerset);
 }
 
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index 864056f..bc59a62 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -1554,9 +1554,7 @@ router_parse_entry_from_string(const char *s, const char *end,
     SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
     smartlist_free(tokens);
   }
-  if (exit_policy_tokens) {
-    smartlist_free(exit_policy_tokens);
-  }
+  smartlist_free(exit_policy_tokens);
   if (area) {
     DUMP_AREA(area, "routerinfo");
     memarea_drop_all(area);
@@ -1672,8 +1670,7 @@ extrainfo_parse_entry_from_string(const char *s, const char *end,
   goto done;
  err:
   dump_desc(s_dup, "extra-info descriptor");
-  if (extrainfo)
-    extrainfo_free(extrainfo);
+  extrainfo_free(extrainfo);
   extrainfo = NULL;
  done:
   if (tokens) {
@@ -2316,8 +2313,7 @@ networkstatus_v2_parse_from_string(const char *s)
   goto done;
  err:
   dump_desc(s_dup, "v2 networkstatus");
-  if (ns)
-    networkstatus_v2_free(ns);
+  networkstatus_v2_free(ns);
   ns = NULL;
  done:
   SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_clear(t));
@@ -2794,8 +2790,7 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out,
   goto done;
  err:
   dump_desc(s_dup, "v3 networkstatus");
-  if (ns)
-    networkstatus_vote_free(ns);
+  networkstatus_vote_free(ns);
   ns = NULL;
  done:
   if (tokens) {
@@ -3859,8 +3854,7 @@ microdescs_parse_from_string(const char *s, const char *eos,
 
     md = NULL;
   next:
-    if (md)
-      microdesc_free(md);
+    microdesc_free(md);
 
     memarea_clear(area);
     smartlist_clear(tokens);
@@ -4264,8 +4258,7 @@ rend_parse_v2_service_descriptor(rend_service_descriptor_t **parsed_out,
   }
   goto done;
  err:
-  if (result)
-    rend_service_descriptor_free(result);
+  rend_service_descriptor_free(result);
   result = NULL;
  done:
   if (tokens) {
-- 
1.5.6.5