commit d478704de889dfc41a72af1187dc52e465ea0cdc Author: Nick Mathewson nickm@torproject.org Date: Wed Oct 21 08:17:30 2015 -0400
Fix a number of unit-test memory leaks, found by valgrind. --- src/test/test_address.c | 10 ++-- src/test/test_dir_handle_get.c | 100 ++++++++++++++++++++-------------------- src/test/test_rendcache.c | 18 ++++---- 3 files changed, 65 insertions(+), 63 deletions(-)
diff --git a/src/test/test_address.c b/src/test/test_address.c index 7ffdcfe..7368b05 100644 --- a/src/test/test_address.c +++ b/src/test/test_address.c @@ -955,7 +955,7 @@ test_address_tor_addr_to_in6(void *ignored) tt_mem_op(res->s6_addr, OP_EQ, expected, 16);
done: - (void)0; + tor_free(a); }
static void @@ -976,7 +976,7 @@ test_address_tor_addr_to_in(void *ignored) tt_int_op(res->s_addr, OP_EQ, 44);
done: - (void)0; + tor_free(a); }
static void @@ -997,7 +997,7 @@ test_address_tor_addr_to_ipv4n(void *ignored) tt_int_op(res, OP_EQ, 43);
done: - (void)0; + tor_free(a); }
static void @@ -1020,7 +1020,7 @@ test_address_tor_addr_to_mapped_ipv4h(void *ignored) tt_int_op(res, OP_EQ, 42);
done: - (void)0; + tor_free(a); }
static void @@ -1044,7 +1044,7 @@ test_address_tor_addr_eq_ipv4h(void *ignored) tt_assert(res);
done: - (void)0; + tor_free(a); }
#define ADDRESS_TEST(name, flags) \ diff --git a/src/test/test_dir_handle_get.c b/src/test/test_dir_handle_get.c index 5a84f17..b6056a9 100644 --- a/src/test/test_dir_handle_get.c +++ b/src/test/test_dir_handle_get.c @@ -5,9 +5,11 @@
#define RENDCOMMON_PRIVATE #define GEOIP_PRIVATE +#define CONNECTION_PRIVATE
#include "or.h" #include "config.h" +#include "connection.h" #include "directory.h" #include "test.h" #include "connection.h" @@ -78,7 +80,7 @@ test_dir_handle_get_bad_request(void *data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -107,7 +109,7 @@ test_dir_handle_get_v1_command_not_found(void *data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -154,7 +156,7 @@ test_dir_handle_get_v1_command(void *data) done: UNMOCK(connection_write_to_buf_impl_); UNMOCK(get_dirportfrontpage); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body); } @@ -180,7 +182,7 @@ test_dir_handle_get_not_found(void *data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -215,7 +217,7 @@ test_dir_handle_get_robots_txt(void *data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body); } @@ -259,7 +261,7 @@ test_dir_handle_get_bytes_txt(void *data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body); } @@ -288,7 +290,7 @@ test_dir_handle_get_rendezvous2_not_found_if_not_encrypted(void *data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -316,7 +318,7 @@ test_dir_handle_get_rendezvous2_on_encrypted_conn_with_invalid_desc_id(
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -349,7 +351,7 @@ test_dir_handle_get_rendezvous2_on_encrypted_conn_not_well_formed(void *data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -378,7 +380,7 @@ test_dir_handle_get_rendezvous2_not_found(void *data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); rend_cache_free_all(); } @@ -470,7 +472,7 @@ test_dir_handle_get_rendezvous2_on_encrypted_conn_success(void *data) NS_UNMOCK(router_get_my_routerinfo); NS_UNMOCK(hid_serv_responsible_for_desc_id);
- tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body); rend_cache_free_all(); @@ -501,7 +503,7 @@ test_dir_handle_get_micro_d_not_found(void *data) done: UNMOCK(connection_write_to_buf_impl_);
- tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -592,7 +594,7 @@ test_dir_handle_get_micro_d(void *data)
if (mock_options) tor_free(mock_options->DataDirectory); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body); smartlist_free(list); @@ -656,7 +658,7 @@ test_dir_handle_get_micro_d_server_busy(void *data) if (mock_options) tor_free(mock_options->DataDirectory);
- tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); smartlist_free(list); microdesc_free_all(); @@ -693,7 +695,7 @@ test_dir_handle_get_networkstatus_bridges_not_found_without_auth(void *data) UNMOCK(get_options); UNMOCK(connection_write_to_buf_impl_); tor_free(mock_options); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -733,7 +735,7 @@ test_dir_handle_get_networkstatus_bridges(void *data) UNMOCK(get_options); UNMOCK(connection_write_to_buf_impl_); tor_free(mock_options); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -770,7 +772,7 @@ test_dir_handle_get_networkstatus_bridges_not_found_wrong_auth(void *data) UNMOCK(get_options); UNMOCK(connection_write_to_buf_impl_); tor_free(mock_options); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -798,7 +800,7 @@ test_dir_handle_get_server_descriptors_not_found(void* data) done: UNMOCK(connection_write_to_buf_impl_); tor_free(mock_options); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -858,7 +860,7 @@ test_dir_handle_get_server_descriptors_all(void* data) done: NS_UNMOCK(router_get_my_routerinfo); UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body);
@@ -962,7 +964,7 @@ test_dir_handle_get_server_descriptors_authority(void* data) NS_UNMOCK(router_get_my_routerinfo); UNMOCK(connection_write_to_buf_impl_); tor_free(mock_routerinfo); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body); crypto_pk_free(identity_pkey); @@ -1033,7 +1035,7 @@ test_dir_handle_get_server_descriptors_fp(void* data) NS_UNMOCK(router_get_my_routerinfo); UNMOCK(connection_write_to_buf_impl_); tor_free(mock_routerinfo); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body); crypto_pk_free(identity_pkey); @@ -1096,7 +1098,7 @@ test_dir_handle_get_server_descriptors_d(void* data) done: UNMOCK(connection_write_to_buf_impl_); tor_free(mock_routerinfo); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body); crypto_pk_free(identity_pkey); @@ -1151,7 +1153,7 @@ test_dir_handle_get_server_descriptors_busy(void* data) UNMOCK(get_options); UNMOCK(connection_write_to_buf_impl_); tor_free(mock_routerinfo); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); crypto_pk_free(identity_pkey);
@@ -1182,7 +1184,7 @@ test_dir_handle_get_server_keys_bad_req(void* data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -1208,7 +1210,7 @@ test_dir_handle_get_server_keys_all_not_found(void* data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -1268,7 +1270,7 @@ test_dir_handle_get_server_keys_all(void* data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body);
@@ -1298,7 +1300,7 @@ test_dir_handle_get_server_keys_authority_not_found(void* data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -1346,7 +1348,7 @@ test_dir_handle_get_server_keys_authority(void* data) done: UNMOCK(get_my_v3_authority_cert); UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body); tor_free(mock_cert); @@ -1374,7 +1376,7 @@ test_dir_handle_get_server_keys_fp_not_found(void* data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -1426,7 +1428,7 @@ test_dir_handle_get_server_keys_fp(void* data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body); clear_dir_servers(); @@ -1455,7 +1457,7 @@ test_dir_handle_get_server_keys_sk_not_found(void* data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -1499,7 +1501,7 @@ test_dir_handle_get_server_keys_sk(void* data) done: UNMOCK(get_my_v3_authority_cert); UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body); } @@ -1526,7 +1528,7 @@ test_dir_handle_get_server_keys_fpsk_not_found(void* data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -1581,7 +1583,7 @@ test_dir_handle_get_server_keys_fpsk(void* data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body);
@@ -1634,7 +1636,7 @@ test_dir_handle_get_server_keys_busy(void* data) done: UNMOCK(get_options); UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(mock_options);
@@ -1693,7 +1695,7 @@ test_dir_handle_get_status_vote_current_consensus_ns_not_enough_sigs(void* d) UNMOCK(connection_write_to_buf_impl_); UNMOCK(get_options);
- tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); smartlist_free(mock_ns_val->voters); tor_free(mock_ns_val); @@ -1732,7 +1734,7 @@ test_dir_handle_get_status_vote_current_consensus_ns_not_found(void* data) done: UNMOCK(connection_write_to_buf_impl_); UNMOCK(get_options); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(mock_options); } @@ -1779,7 +1781,7 @@ status_vote_current_consensus_ns_test(char **header, char **body,
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); }
static void @@ -1900,7 +1902,7 @@ test_dir_handle_get_status_vote_current_not_found(void* data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -1923,7 +1925,7 @@ status_vote_current_d_test(char **header, char **body, size_t *body_l)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); }
static void @@ -1943,7 +1945,7 @@ status_vote_next_d_test(char **header, char **body, size_t *body_l)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); }
static void @@ -2067,7 +2069,7 @@ test_dir_handle_get_status_vote_next_not_found(void* data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -2086,7 +2088,7 @@ status_vote_next_consensus_test(char **header, char **body, size_t *body_used) body, body_used, 18, 0); done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); }
static void @@ -2126,7 +2128,7 @@ test_dir_handle_get_status_vote_current_authority_not_found(void* data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -2150,7 +2152,7 @@ test_dir_handle_get_status_vote_next_authority_not_found(void* data)
done: UNMOCK(connection_write_to_buf_impl_); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); }
@@ -2249,7 +2251,7 @@ test_dir_handle_get_status_vote_next_consensus_signatures_not_found(void* data) tt_str_op(NOT_FOUND, OP_EQ, header);
done: - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body); } @@ -2311,7 +2313,7 @@ test_dir_handle_get_status_vote_next_consensus_signatures_busy(void* data) done: UNMOCK(get_options); NS_UNMOCK(dirvote_get_pending_detached_signatures); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(body); tor_free(mock_options); @@ -2382,7 +2384,7 @@ test_dir_handle_get_status_vote_next_authority(void* data) done: UNMOCK(connection_write_to_buf_impl_); UNMOCK(get_my_v3_authority_cert); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(mock_cert);
@@ -2461,7 +2463,7 @@ test_dir_handle_get_status_vote_current_authority(void* data) done: UNMOCK(connection_write_to_buf_impl_); UNMOCK(get_my_v3_authority_cert); - tor_free(conn); + connection_free_(TO_CONN(conn)); tor_free(header); tor_free(mock_cert);
diff --git a/src/test/test_rendcache.c b/src/test/test_rendcache.c index e484858..087d198 100644 --- a/src/test/test_rendcache.c +++ b/src/test/test_rendcache.c @@ -83,7 +83,7 @@ test_rend_cache_lookup_entry(void *data) tt_str_op(entry->desc, OP_EQ, desc_holder->desc_str);
done: - tor_free(desc_holder); + rend_encoded_v2_service_descriptor_free(desc_holder); tor_free(entry); tor_free(service_id); } @@ -164,7 +164,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
// Test too old descriptor rend_cache_init(); - tor_free(desc_holder); + rend_encoded_v2_service_descriptor_free(desc_holder); tor_free(service_id);
generate_desc(TIME_IN_THE_PAST, &desc_holder, &service_id, 3); @@ -179,7 +179,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
// Test too new descriptor (in the future) rend_cache_init(); - tor_free(desc_holder); + rend_encoded_v2_service_descriptor_free(desc_holder); tor_free(service_id);
generate_desc(TIME_IN_THE_FUTURE, &desc_holder, &service_id, 3); @@ -194,7 +194,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
// Test when a descriptor is already in the cache rend_cache_init(); - tor_free(desc_holder); + rend_encoded_v2_service_descriptor_free(desc_holder); tor_free(service_id); tor_free(entry);
@@ -218,7 +218,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
// Test unsuccessful decrypting of introduction points rend_cache_init(); - tor_free(desc_holder); + rend_encoded_v2_service_descriptor_free(desc_holder); tor_free(service_id);
generate_desc(RECENT_TIME, &desc_holder, &service_id, 3); @@ -236,7 +236,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
// Test successful run when we have REND_BASIC_AUTH but not cookie rend_cache_init(); - tor_free(desc_holder); + rend_encoded_v2_service_descriptor_free(desc_holder); tor_free(service_id);
generate_desc(RECENT_TIME, &desc_holder, &service_id, 3); @@ -251,7 +251,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
// Test when we have no introduction points rend_cache_init(); - tor_free(desc_holder); + rend_encoded_v2_service_descriptor_free(desc_holder); tor_free(service_id);
generate_desc(RECENT_TIME, &desc_holder, &service_id, 0); @@ -265,7 +265,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
// Test when we have too many intro points rend_cache_init(); - tor_free(desc_holder); + rend_encoded_v2_service_descriptor_free(desc_holder); tor_free(service_id);
generate_desc(RECENT_TIME, &desc_holder, &service_id, MAX_INTRO_POINTS+1); @@ -487,7 +487,7 @@ test_rend_cache_store_v2_desc_as_dir(void *data) done: NS_UNMOCK(router_get_my_routerinfo); NS_UNMOCK(hid_serv_responsible_for_desc_id); - tor_free(desc_holder); + rend_encoded_v2_service_descriptor_free(desc_holder); tor_free(service_id); }