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
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -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;
}

+2 −4
Original line number Diff line number Diff line
@@ -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);
}

+1 −2
Original line number Diff line number Diff line
@@ -953,7 +953,6 @@ const char *
escaped(const char *s)
{
  static char *_escaped_val = NULL;
  if (_escaped_val)
  tor_free(_escaped_val);

  if (s)
+6 −9
Original line number Diff line number Diff line
@@ -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);
}
+18 −32
Original line number Diff line number Diff line
@@ -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 */
Loading