diff options
author | George Kadianakis <desnacked@riseup.net> | 2019-04-08 16:18:44 +0300 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2019-05-03 18:15:11 +0300 |
commit | f5635989b06260710b282e75be7b731e2846f700 (patch) | |
tree | 62c67a6dfd0618a65470c1975d54a7c79217f9c5 /src/core/or/crypt_path.c | |
parent | 18d61c0e6e71dace189384c8af7f4fec158969b3 (diff) | |
download | tor-f5635989b06260710b282e75be7b731e2846f700.tar.gz tor-f5635989b06260710b282e75be7b731e2846f700.zip |
Hiding crypt_path_t: Create a constructor for crypt_path_t.
We are using an opaque pointer so the structure needs to be allocated on the
heap. This means we now need a constructor for crypt_path_t.
Also modify all places initializing a crypt_path_t to use the constructor.
Diffstat (limited to 'src/core/or/crypt_path.c')
-rw-r--r-- | src/core/or/crypt_path.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/core/or/crypt_path.c b/src/core/or/crypt_path.c index 54f5623d32..975af6c16d 100644 --- a/src/core/or/crypt_path.c +++ b/src/core/or/crypt_path.c @@ -26,6 +26,17 @@ #include "core/or/crypt_path_st.h" #include "core/or/cell_st.h" +/** Initialize and return a minimal crypt_path_t */ +crypt_path_t * +crypt_path_new(void) +{ + crypt_path_t *cpath = tor_malloc_zero(sizeof(crypt_path_t)); + cpath->magic = CRYPT_PATH_MAGIC; + cpath->private = tor_malloc_zero(sizeof(struct crypt_path_private_t)); + + return cpath; +} + /** Add <b>new_hop</b> to the end of the doubly-linked-list <b>head_ptr</b>. * This function is used to extend cpath by another hop. */ @@ -49,12 +60,11 @@ onion_append_to_cpath(crypt_path_t **head_ptr, crypt_path_t *new_hop) int onion_append_hop(crypt_path_t **head_ptr, extend_info_t *choice) { - crypt_path_t *hop = tor_malloc_zero(sizeof(crypt_path_t)); + crypt_path_t *hop = crypt_path_new(); /* link hop into the cpath, at the end. */ onion_append_to_cpath(head_ptr, hop); - hop->magic = CRYPT_PATH_MAGIC; hop->state = CPATH_STATE_CLOSED; hop->extend_info = extend_info_dup(choice); @@ -158,6 +168,7 @@ circuit_free_cpath_node(crypt_path_t *victim) onion_handshake_state_release(&victim->handshake_state); crypto_dh_free(victim->rend_dh_handshake_state); extend_info_free(victim->extend_info); + tor_free(victim->private); memwipe(victim, 0xBB, sizeof(crypt_path_t)); /* poison memory */ tor_free(victim); |