diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-12-04 15:09:18 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-12-08 14:47:19 -0500 |
commit | db024adc90069ce9961f3993aba1b7372f09d77a (patch) | |
tree | bf42a6612ab7f26e6886604ba08e924dca6a28c6 /src/or | |
parent | 176ad729d9b1ddeccdb3e721b5ab1bf64646223f (diff) | |
download | tor-db024adc90069ce9961f3993aba1b7372f09d77a.tar.gz tor-db024adc90069ce9961f3993aba1b7372f09d77a.zip |
Switch to a safer FREE_AND_NULL implementation
This one only evaluates the input once, so it cannot mess up even if
there are side effects.
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/hs_service.c | 2 | ||||
-rw-r--r-- | src/or/hs_service.h | 9 | ||||
-rw-r--r-- | src/or/networkstatus.h | 3 | ||||
-rw-r--r-- | src/or/policies.h | 3 | ||||
-rw-r--r-- | src/or/rendcache.c | 6 | ||||
-rw-r--r-- | src/or/rendcache.h | 10 | ||||
-rw-r--r-- | src/or/rendservice.c | 6 | ||||
-rw-r--r-- | src/or/router.h | 3 | ||||
-rw-r--r-- | src/or/routerlist.c | 2 | ||||
-rw-r--r-- | src/or/shared_random_state.c | 2 |
10 files changed, 27 insertions, 19 deletions
diff --git a/src/or/hs_service.c b/src/or/hs_service.c index e88fb23892..1f93c2d520 100644 --- a/src/or/hs_service.c +++ b/src/or/hs_service.c @@ -370,7 +370,7 @@ service_intro_point_free_(hs_service_intro_point_t *ip) static void service_intro_point_free_void(void *obj) { - service_intro_point_free(obj); + service_intro_point_free_(obj); } /* Return a newly allocated service intro point and fully initialized from the diff --git a/src/or/hs_service.h b/src/or/hs_service.h index b759030166..f933ba6ab1 100644 --- a/src/or/hs_service.h +++ b/src/or/hs_service.h @@ -295,8 +295,9 @@ STATIC hs_service_intro_point_t *service_intro_point_new( const extend_info_t *ei, unsigned int is_legacy); STATIC void service_intro_point_free_(hs_service_intro_point_t *ip); -#define service_intro_point_free(ip) \ - FREE_AND_NULL(service_intro_point, (ip)) +#define service_intro_point_free(ip) \ + FREE_AND_NULL_UNMATCHED(hs_service_intro_point_t, \ + service_intro_point_free_, (ip)) STATIC void service_intro_point_add(digest256map_t *map, hs_service_intro_point_t *ip); STATIC void service_intro_point_remove(const hs_service_t *service, @@ -330,7 +331,9 @@ STATIC char * encode_desc_rev_counter_for_state(const hs_service_descriptor_t *desc); STATIC void service_descriptor_free_(hs_service_descriptor_t *desc); -#define service_descriptor_free(d) FREE_AND_NULL(service_descriptor, (d)) +#define service_descriptor_free(d) \ + FREE_AND_NULL_UNMATCHED(hs_service_descriptor_t, \ + service_descriptor_free_, (d)) STATIC uint64_t check_state_line_for_service_rev_counter(const char *state_line, diff --git a/src/or/networkstatus.h b/src/or/networkstatus.h index f62b5d2409..37350bb1b3 100644 --- a/src/or/networkstatus.h +++ b/src/or/networkstatus.h @@ -21,7 +21,8 @@ int router_reload_consensus_networkstatus(void); void routerstatus_free_(routerstatus_t *rs); #define routerstatus_free(rs) FREE_AND_NULL(routerstatus, (rs)) void networkstatus_vote_free_(networkstatus_t *ns); -#define networkstatus_vote_free(ns) FREE_AND_NULL(networkstatus_vote, (ns)) +#define networkstatus_vote_free(ns) \ + FREE_AND_NULL_UNMATCHED(networkstatus_t, networkstatus_vote_free_, (ns)) networkstatus_voter_info_t *networkstatus_get_voter_by_id( networkstatus_t *vote, const char *identity); diff --git a/src/or/policies.h b/src/or/policies.h index 062f330183..451a7a7f36 100644 --- a/src/or/policies.h +++ b/src/or/policies.h @@ -116,7 +116,8 @@ int policy_write_item(char *buf, size_t buflen, const addr_policy_t *item, int format_for_desc); void addr_policy_list_free_(smartlist_t *p); -#define addr_policy_list_free(lst) FREE_AND_NULL(addr_policy_list, (lst)) +#define addr_policy_list_free(lst) \ + FREE_AND_NULL_UNMATCHED(smartlist_t, addr_policy_list_free_, (lst)) void addr_policy_free_(addr_policy_t *p); #define addr_policy_free(p) FREE_AND_NULL(addr_policy, (p)) void policies_free_all(void); diff --git a/src/or/rendcache.c b/src/or/rendcache.c index fa454321d0..6f56df6718 100644 --- a/src/or/rendcache.c +++ b/src/or/rendcache.c @@ -131,7 +131,7 @@ rend_cache_failure_intro_entry_free_(rend_cache_failure_intro_t *entry) static void rend_cache_failure_intro_entry_free_void(void *entry) { - rend_cache_failure_intro_entry_free(entry); + rend_cache_failure_intro_entry_free_(entry); } /** Allocate a rend cache failure intro object and return it. <b>failure</b> @@ -165,7 +165,7 @@ rend_cache_failure_entry_free_(rend_cache_failure_t *entry) STATIC void rend_cache_failure_entry_free_void(void *entry) { - rend_cache_failure_entry_free(entry); + rend_cache_failure_entry_free_(entry); } /** Allocate a rend cache failure object and return it. This function can @@ -219,7 +219,7 @@ rend_cache_entry_free_(rend_cache_entry_t *e) static void rend_cache_entry_free_void(void *p) { - rend_cache_entry_free(p); + rend_cache_entry_free_(p); } /** Free all storage held by the service descriptor cache. */ diff --git a/src/or/rendcache.h b/src/or/rendcache.h index 66b48e0320..c1e9207a95 100644 --- a/src/or/rendcache.h +++ b/src/or/rendcache.h @@ -94,11 +94,13 @@ STATIC void rend_cache_entry_free_(rend_cache_entry_t *e); #define rend_cache_entry_free(e) FREE_AND_NULL(rend_cache_entry, (e)) STATIC void rend_cache_failure_intro_entry_free_(rend_cache_failure_intro_t *entry); -#define rend_cache_failure_intro_entry_free(e) \ - FREE_AND_NULL(rend_cache_failure_intro_entry, (e)) +#define rend_cache_failure_intro_entry_free(e) \ + FREE_AND_NULL_UNMATCHED(rend_cache_failure_intro_t, \ + rend_cache_failure_intro_entry_free_, (e)) STATIC void rend_cache_failure_entry_free_(rend_cache_failure_t *entry); -#define rend_cache_failure_entry_free(e) \ - FREE_AND_NULL(rend_cache_failure_entry, (e)) +#define rend_cache_failure_entry_free(e) \ + FREE_AND_NULL_UNMATCHED(rend_cache_failure_t, \ + rend_cache_failure_entry_free_, (e)) STATIC int cache_failure_intro_lookup(const uint8_t *identity, const char *service_id, rend_cache_failure_intro_t diff --git a/src/or/rendservice.c b/src/or/rendservice.c index 568afe79b7..3e318f73fe 100644 --- a/src/or/rendservice.c +++ b/src/or/rendservice.c @@ -174,7 +174,7 @@ rend_authorized_client_free_(rend_authorized_client_t *client) static void rend_authorized_client_strmap_item_free(void *authorized_client) { - rend_authorized_client_free(authorized_client); + rend_authorized_client_free_(authorized_client); } /** Release the storage held by <b>service</b>. @@ -3726,7 +3726,7 @@ upload_service_descriptor(rend_service_t *service) } /* Free memory for descriptors. */ for (i = 0; i < smartlist_len(descs); i++) - rend_encoded_v2_service_descriptor_free(smartlist_get(descs, i)); + rend_encoded_v2_service_descriptor_free_(smartlist_get(descs, i)); smartlist_clear(descs); /* Update next upload time. */ if (seconds_valid - REND_TIME_PERIOD_OVERLAPPING_V2_DESCS @@ -3757,7 +3757,7 @@ upload_service_descriptor(rend_service_t *service) } /* Free memory for descriptors. */ for (i = 0; i < smartlist_len(descs); i++) - rend_encoded_v2_service_descriptor_free(smartlist_get(descs, i)); + rend_encoded_v2_service_descriptor_free_(smartlist_get(descs, i)); smartlist_clear(descs); } } diff --git a/src/or/router.h b/src/or/router.h index cd953da7aa..e282b9975d 100644 --- a/src/or/router.h +++ b/src/or/router.h @@ -37,7 +37,8 @@ int get_onion_key_grace_period(void); di_digest256_map_t *construct_ntor_key_map(void); void ntor_key_map_free_(di_digest256_map_t *map); -#define ntor_key_map_free(map) FREE_AND_NULL(ntor_key_map, (map)) +#define ntor_key_map_free(map) \ + FREE_AND_NULL_UNMATCHED(di_digest256_map_t, ntor_key_map_free_, (map)) int router_initialize_tls_context(void); int init_keys(void); diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 877479969f..0236761eb3 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -3268,7 +3268,7 @@ signed_descriptor_from_routerinfo(routerinfo_t *ri) static void extrainfo_free_void(void *e) { - extrainfo_free(e); + extrainfo_free_(e); } /** Free all storage held by a routerlist <b>rl</b>. */ diff --git a/src/or/shared_random_state.c b/src/or/shared_random_state.c index ae904cfda3..8c5a497bb3 100644 --- a/src/or/shared_random_state.c +++ b/src/or/shared_random_state.c @@ -271,7 +271,7 @@ commit_add_to_state(sr_commit_t *commit, sr_state_t *state) static void commit_free_(void *p) { - sr_commit_free(p); + sr_commit_free_(p); } /* Free a state that was allocated with state_new(). */ |